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
    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 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 Queue handoverPrintQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE, true, false, false);
    }

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

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


    @Bean
    public Queue orderStockQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE, true);
    }

    @Bean
    public Queue productInfoChangeQueue() {
        return new Queue(activeProfile + "-" + RabbitConstants.Queue.PRODUCT_INFO_CHANGE_QUEUE, true);
    }

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

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

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

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

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

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


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

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

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