package com.czg.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.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.HashMap;
import java.util.Map;


/**
 * @author GYJoker
 */
@Configuration
public class RabbitConfig {

    @Value("${spring.profiles.active}")
    private String activeProfile;

    @Bean
    @Primary
    public DirectExchange directExchange() {
        return new DirectExchange(activeProfile + "-" + RabbitConstants.Exchange.CASH_EXCHANGE);
    }

    //------------------------------------------------------ 商家入驻
    @Bean
    public Queue entryManagerQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.SHOP_ENTRY_MANAGER, true, false, false);
    }

    @Bean
    public Binding entryManagerExchange(Queue entryManagerQueue, DirectExchange exchange) {
        return BindingBuilder.bind(entryManagerQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.SHOP_ENTRY_MANAGER);
    }

    //------------------------------------------------------订单打印队列
    @Bean
    public Queue orderPrintQueue() {
        // 创建一个用于存储队列参数的 Map
        Map<String, Object> args = new HashMap<>();
        // 设置消息过期时间为 180000 毫秒（即 180 秒）
        args.put("x-message-ttl", 180000);
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, args);
    }

    @Bean
    public Binding bindingOrderPrintExchange(Queue orderPrintQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderPrintQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE);
    }


    //------------------------------------------------------订单厨房票
    @Bean
    public Queue orderMachinePrintQueue() {
        // 创建一个用于存储队列参数的 Map
//        Map<String, Object> args = new HashMap<>();
        // 设置消息过期时间为 180000 毫秒（即 180 秒）
//        args.put("x-message-ttl", 180000);
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE, true, false, false);
    }

    @Bean
    public Binding bindingOrderMachinePrintExchange(Queue orderMachinePrintQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderMachinePrintQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE);
    }


    //------------------------------------------------------其它打印消息打票
    @Bean
    public Queue otherPrintQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_QUEUE, true, false, false);
    }

    @Bean
    public Binding bindingOtherPrintExchange(Queue otherPrintQueue, DirectExchange exchange) {
        return BindingBuilder.bind(otherPrintQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_QUEUE);
    }

    @Bean
    public Queue otherPrintLocalQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_LOCAL_QUEUE, true, false, false);
    }

    @Bean
    public Binding bindingOtherPrintLocalExchange(Queue otherPrintLocalQueue, DirectExchange exchange) {
        return BindingBuilder.bind(otherPrintLocalQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.OTHER_PRINT_LOCAL_QUEUE);
    }

    //------------------------------------------------------订单取消
    @Bean
    public Queue orderCancelQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_CANCEL_QUEUE, true);
    }

    @Bean
    public Binding bindingOrderCancelExchange(Queue orderCancelQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderCancelQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_CANCEL_QUEUE);
    }

    //------------------------------------------------------ 订单库存更新
    @Bean
    public Queue orderStockQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE, true);
    }

    @Bean
    public Binding bindingOrderStockExchange(Queue orderStockQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderStockQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE);
    }


    //------------------------------------------------------ 商品信息更新
    @Bean
    public Queue productInfoChangeQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE, true);
    }

    @Bean
    public Binding bindingProductInfoChange(Queue productInfoChangeQueue, DirectExchange exchange) {
        return BindingBuilder.bind(productInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE);
    }

    //------------------------------------------------------ 耗材信息更新
    @Bean
    public Queue consInfoChangeQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.CONS_INFO_CHANGE_QUEUE, true);
    }

    @Bean
    public Binding bindingConsInfoChange(Queue consInfoChangeQueue, DirectExchange exchange) {
        return BindingBuilder.bind(consInfoChangeQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.CONS_INFO_CHANGE_QUEUE);
    }

    //------------------------------------------------------ 订单退款
    @Bean
    public Queue orderRefundQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_REFUND_QUEUE, true);
    }

    @Bean
    public Binding bindingOrderRefundExchange(Queue orderRefundQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderRefundQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_REFUND_QUEUE);
    }


    //------------------------------------------------------ 申请短信模板队列

    /**
     * 1,2,applySmsTemp  模版审核
     * 1,2,sendMarkSms 发送营销短信
     * 1,2,sendWechatTemp 发送微信模版消息
     *
     */
    @Bean
    public Queue applySmsTemplateQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.APPLY_SMS_TEMPLATE_QUEUE, true);
    }

    @Bean
    public Binding bindingApplySmsTemplateExchange(Queue applySmsTemplateQueue, DirectExchange exchange) {
        return BindingBuilder.bind(applySmsTemplateQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.APPLY_SMS_TEMPLATE_QUEUE);
    }

    //------------------------------------------------------ 生日礼品短信队列
    @Bean
    public Queue birthdayGiftSmsQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.BIRTHDAY_GIFT_SMS_QUEUE, true);
    }

    @Bean
    public Binding bindingBirthdayGiftSmsExchange(Queue birthdayGiftSmsQueue, DirectExchange exchange) {
        return BindingBuilder.bind(birthdayGiftSmsQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.BIRTHDAY_GIFT_SMS_QUEUE);
    }

    //------------------------------------------------------ 订单商品状态
    @Bean
    public Queue orderProductStatusQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRODUCT_STATUS_QUEUE, true);
    }

    @Bean
    public Binding bindingOrderProductStatusExchange(Queue orderProductStatusQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderProductStatusQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRODUCT_STATUS_QUEUE);
    }


    //------------------------------------------------------ 订单详情状态
    @Bean
    public Queue orderDetailStatusQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_DETAIL_STATUS_QUEUE, true);
    }

    @Bean
    public Binding bindingOrderDetailStatusExchange(Queue orderDetailStatusQueue, DirectExchange exchange) {
        return BindingBuilder.bind(orderDetailStatusQueue).to(exchange).with(activeProfile + "-" + RabbitConstants.Queue.ORDER_DETAIL_STATUS_QUEUE);
    }
}
