package com.muchinfo.mtp3century.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

@Configuration
public class RabbitConfig {

    @Value("${new_web_configuration.app.exchange}")
    private String exchangeName;

    @Value("${new_web_configuration.app.durable}")
    private boolean durableName;

    @Value("${new_web_configuration.app.autoDelete}")
    private boolean autoDeleteName;

    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
        placeholderConfigurer.setIgnoreUnresolvablePlaceholders(true); // 忽略无法解析的占位符
        return placeholderConfigurer;
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange(exchangeName, durableName, autoDeleteName);
    }

    @Bean
    public Queue bankQueue() {
        return new Queue("bankQueue");
    }

    @Bean
    public Queue exInOutMoneyQueue() {
        return new Queue("exInOutMoneyQueue");
    }

    @Bean
    public Queue moneyQueue() {
        return new Queue("moneyQueue");
    }

    @Bean
    public Queue loginStatusMsgQueue() {
        return new Queue("loginStatusMsgQueue");
    }

    @Bean
    public Queue tradeCpRspQueue() {
        return new Queue("tradeCpRspQueue");
    }

    @Bean
    public Queue orderQueue() {
        return new Queue("orderQueue");
    }

    @Bean
    public Queue warehouseQueue() {
        return new Queue("warehouseQueue");
    }

    @Bean
    Binding bindingBankQueue() {
        return BindingBuilder.bind(bankQueue()).to(exchange()).with("bank_rsp");
    }

    @Bean
    Binding bindingExInOutMoneyQueue() {
        return BindingBuilder.bind(exInOutMoneyQueue()).to(exchange()).with("ex_money_rsp");
    }

    @Bean
    Binding bindingMoneyQueue() {
        return BindingBuilder.bind(moneyQueue()).to(exchange()).with("money_rsp");
    }

    @Bean
    Binding bindingLoginStatusMsgQueue() {
        return BindingBuilder.bind(loginStatusMsgQueue()).to(exchange()).with("user_rsp");
    }

    @Bean
    Binding bindingTradeCpRspQueue() {
        return BindingBuilder.bind(tradeCpRspQueue()).to(exchange()).with("trade_cp_manage_rsp");
    }

    @Bean
    Binding bindingOrderQueue() {
        return BindingBuilder.bind(orderQueue()).to(exchange()).with("order_rsp");
    }

    @Bean
    Binding bindingWarehouseQueue() {
        return BindingBuilder.bind(warehouseQueue()).to(exchange()).with("wr_response");
    }
}
