/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @Title: OrderCallBackConfig
 * @Package cn.freemud.amp.config
 * @Description:
 * @author: ping.wu
 * @date: 2019/4/16 14:16
 * @version V1.0
 * @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
package cn.freemud.amp.config;

import cn.freemud.amp.service.OrderCallBackMQService;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

public class OrderCallBackConfig {

    public static final String EXCHANGE_NAME = "call-back-service-topic-exchange";
    public static final String QUEUE_NAME = "order-call-back-queue";
    public static final String QUEUE_ROUTING_KEY = "order-call-back-queue-routing-key";

    ///开放平台
    public static final String TOPIC_EXCHANGE_NAME = "topic-Exchange";
    public static final String OPEN_PLATFORM_ORDER_STATUS_CHANGE_PUSH_QUEUE_NAME = "open-platform-order-status-change-push-queue";
    public static final String OPEN_PLATFORM_ORDER_STATUS_CHANGE_PUSH_ROUTING_KEY = "open-platform-order-status-change-routing-key";

    public static final String WECHAT_REPORT_QUEUE_ROUTING_KEY="wechat-report-queue-routing-key";

    /**
     * 定义基于Fanout 的Exchange。
     * 基于这个代码，也可以非常方便的定义其他的Exchange类型。
     *
     * @return Fanout Exchange
     */
    @Bean
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    /**
     * 写入RabbitMQ使用的默认队列
     *
     * @return
     */
    @Bean
    public Queue pushOrderQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    /**
     * 绑定消息队列
     *
     * @param pushOrderQueue 消息队列
     * @param exchange       RabbitMQ Fanout Exchange
     * @return 消息队列绑定
     */
    @Bean
    Binding bindingMail(Queue pushOrderQueue, Exchange exchange) {
        return BindingBuilder.bind(pushOrderQueue).to(exchange).with(QUEUE_ROUTING_KEY).noargs();
    }

    @Bean(name = "topicExchange")
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange(TOPIC_EXCHANGE_NAME).durable(true).build();
    }

    @Bean(name = "orderStatusChangeQueue")
    public Queue orderStatusChangeQueue() {
        return QueueBuilder.durable(OPEN_PLATFORM_ORDER_STATUS_CHANGE_PUSH_QUEUE_NAME).build();
    }

    @Bean
    Binding bindingOrderStatus(@Qualifier("orderStatusChangeQueue") Queue orderStatusChangeQueue, @Qualifier("topicExchange") Exchange topicExchange) {
        return BindingBuilder.bind(orderStatusChangeQueue).to(topicExchange).with(OPEN_PLATFORM_ORDER_STATUS_CHANGE_PUSH_ROUTING_KEY).noargs();
    }

    @Bean
    public OrderCallBackMQService orderMQService() {
        return new OrderCallBackMQService();
    }

}
