package com.jy.business.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableRabbit
@Configuration
public class RabbitConfig {

    /**
     * 资金流水队列
     */
    public static final String TRANSACTIONS_QUEUE = "transactionsQueue";

    /**
     * 合同队列
     */
    public static final String CONTRACT_QUEUE = "contractQueue";

    /**
     * 到账认领
     */
    public static final String CONTRACT_FUND_RECEIVED_QUEUE = "contractFundReceivedQueue";

    /**
     * 确认到账
     */
    public static final String CONFIRM_RECEIVED_QUEUE = "confirmFundReceivedQueue";

    /**
     * jy项目交换机
     */
    public static final String JY_DIRECT_EXCHANGE = "jyDirectExchange";

    /**
     * 创建一个资金流水队列
     */
    @Bean
    public Queue transactionsQueue() {
        return new Queue(TRANSACTIONS_QUEUE, true);
    }

    /**
     * 创建一个合同队列
     */
    @Bean
    public Queue contractQueue() {
        return new Queue(CONTRACT_QUEUE, true);
    }

    /**
     * 创建一个合同到账队列
     */
    @Bean
    public Queue contractFundReceivedQueue() {
        return new Queue(CONTRACT_FUND_RECEIVED_QUEUE, true);
    }

    /**
     * 创建一个确认到账队列
     */
    @Bean
    public Queue confirmFundReceivedQueue() {
        return new Queue(CONFIRM_RECEIVED_QUEUE, true);
    }

    /**
     * 创建一个Direct类型的交换机
     */
    @Bean
    public DirectExchange jyDirectExchange() {
        return new DirectExchange(JY_DIRECT_EXCHANGE, true, false);
    }

    /**
     * 绑定交换机和资金流水队列
     */
    @Bean
    public Binding transactionsBinding() {
        return BindingBuilder.bind(transactionsQueue()).to(jyDirectExchange()).withQueueName();
    }

    /**
     * 绑定交换机和合同队列
     */
    @Bean
    public Binding contractBinding() {
        return BindingBuilder.bind(contractQueue()).to(jyDirectExchange()).withQueueName();
    }

    /**
     * 绑定交换机和合同到账队列
     */
    @Bean
    public Binding contractFundReceivedBinding() {
        return BindingBuilder.bind(contractFundReceivedQueue()).to(jyDirectExchange()).withQueueName();
    }

    /**
     * 绑定交换机和确认到账队列
     */
    @Bean
    public Binding confirmFundReceivedBinding() {
        return BindingBuilder.bind(confirmFundReceivedQueue()).to(jyDirectExchange()).withQueueName();
    }

}
