package com.yida.data.rabbit.configure;

import com.yida.data.rabbit.constant.RabbitConstant;
import com.yida.data.rabbit.util.RabbitUtil;
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.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfigure {

    @Bean
    public RabbitUtil rabbitUtil() {
        return new RabbitUtil();
    }

    /**
     * 亲情电话交换机
     *
     * @return
     */
    @Bean
    public DirectExchange telephoneExchange() {
        return new DirectExchange(RabbitConstant.TELEPHONE_EXCHANGE);
    }

    /**
     * 亲情电话-套餐队列
     *
     * @return
     */
    @Bean
    public Queue telephoneMealQueue() {
        return new Queue(RabbitConstant.TELEPHONE_MEAL_QUEUE, true);
    }

    /**
     * 亲情电话-套餐交换机绑定
     */
    @Bean
    public Binding telephoneMealBinding(@Qualifier("telephoneMealQueue") Queue queue,
        @Qualifier("telephoneExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.TELEPHONE_MEAL_KEY);
    }

    /**
     * 学生邀请队列
     *
     * @return org.springframework.amqp.core.Queue
     * @author ZYJ
     * @date 2021/8/25 11:00
     */
    @Bean
    public Queue inviteImportQueue() {
        return new Queue(RabbitConstant.INVITE_IMPORT_QUEUE, true);
    }

    /**
     * 学生邀请交换机
     *
     * @return org.springframework.amqp.core.DirectExchange
     * @author ZYJ
     * @date 2021/8/25 11:01
     */
    @Bean
    public DirectExchange inviteImportExchange() {
        return new DirectExchange(RabbitConstant.INVITE_IMPORT_EXCHANGE);
    }

    /**
     * 学生邀请队列和交换机绑定
     *
     * @param queue    学生邀请队列
     * @param exchange 学生邀请交换机
     * @return org.springframework.amqp.core.Binding
     * @author ZYJ
     * @date 2021/8/25 11:02
     */
    @Bean
    public Binding inviteImportBinding(@Qualifier("inviteImportQueue") Queue queue,
        @Qualifier("inviteImportExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.INVITE_IMPORT_KEY);
    }

    /**
     * 图集点赞和取消赞队列
     *
     * @return org.springframework.amqp.core.Queue
     * @author ZYJ
     * @date 2021/9/7 11:30
     */
    @Bean
    public Queue atlasLikeQueue() {
        return new Queue(RabbitConstant.ATLAS_LIKE_QUEUE, true);
    }

    /**
     * 图集点赞和取消赞交换机
     *
     * @return org.springframework.amqp.core.DirectExchange
     * @author ZYJ
     * @date 2021/9/7 11:30
     */
    @Bean
    public DirectExchange atlasLikeExchange() {
        return new DirectExchange(RabbitConstant.ATLAS_LIKE_EXCHANGE);
    }

    /**
     * 图集点赞和取消赞绑定
     *
     * @param queue    图集点赞和取消赞队列
     * @param exchange 图集点赞和取消赞交换机
     * @return org.springframework.amqp.core.Binding
     * @author ZYJ
     * @date 2021/9/7 11:31
     */
    @Bean
    public Binding atlasLikeBinding(@Qualifier("atlasLikeQueue") Queue queue,
        @Qualifier("atlasLikeExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.ATLAS_LIKE_KEY);
    }


    /**
     * 电子学生证定位队列
     *
     * @return
     */
    @Bean
    public Queue cardLocationQueue() {
        return new Queue(RabbitConstant.CARD_810A_MSG_QUEUE, true);
    }

    /**
     * 电子学生证交换机
     *
     * @return
     */
    @Bean
    public DirectExchange cardExchange() {
        return new DirectExchange(RabbitConstant.CARD_EXCHANGE);
    }

    /**
     * 电子学生证位置信息绑定
     */
    @Bean
    public Binding cardLocationBinding(@Qualifier("cardLocationQueue") Queue queue,
        @Qualifier("cardExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.CARD_810A_MSG_KEY);
    }

    /**
     * 消息处理交换机
     *
     * @return
     */
    @Bean
    public DirectExchange msgExchange() {
        return new DirectExchange(RabbitConstant.MSG_EXCHANGE);
    }


    /**
     * 保存系统通知队列
     *
     * @return
     */
    @Bean
    public Queue msgNoticeSysSaveQueue() {
        return new Queue(RabbitConstant.MSG_NOTICE_SYS_SAVE_QUEUE, true);
    }

    /**
     * 保存系统通知绑定
     */
    @Bean
    public Binding msgNoticeSysSaveBinding(@Qualifier("msgNoticeSysSaveQueue") Queue queue,
        @Qualifier("msgExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.MSG_NOTICE_SYS_SAVE_KEY);
    }

    /**
     * websocket消息消费队列
     *
     * @return
     */
    @Bean
    public Queue msgWebsocketQueue() {
        return new Queue(RabbitConstant.MSG_WEBSOCKET_QUEUE, true);
    }

    /**
     * websocket消息消费绑定
     */
    @Bean
    public Binding msgWebsocketBinding(@Qualifier("msgWebsocketQueue") Queue queue,
        @Qualifier("msgExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConstant.MSG_WEBSOCKET_KEY);
    }
}
