package com.clx.performance.config;

import com.clx.performance.constant.RabbitKeyOrderChildConstants;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

/**
 * @Author: aiqingguo
 * @Description: 运单 MQ
 * @Date: 2023-10-12 16:27:30
 * @Version: 1.0
 */
@Configuration
public class RabbitOrderChildConfig {

    @Bean
    public DirectExchange orderChildDefaultExchange() {
        return new DirectExchange(RabbitKeyOrderChildConstants.DEFAULT_EXCHANGE);
    }

    @Bean
    public Queue orderChildDefaultDelayQueue() {
        Map<String, Object> params = new HashMap<>(8);
        params.put("x-message-ttl", 15 * 60 * 1000);
        params.put("x-max-length", 5000000);
        params.put("x-dead-letter-exchange", RabbitKeyOrderChildConstants.DEFAULT_EXCHANGE);
        params.put("x-dead-letter-routing-key", RabbitKeyOrderChildConstants.DEFAULT_DEAD_ROUTING_KEY);
        return new Queue(RabbitKeyOrderChildConstants.DEFAULT_DELAY_QUEUE, true, false, false, params);
    }
    @Bean
    public Binding orderChildDefaultDelayQueueBinding() {
        return BindingBuilder.bind(orderChildDefaultDelayQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.DEFAULT_DELAY_ROUTING_KEY);
    }

    @Bean
    public Queue orderChildDefaultDeadQueue() {
        return new Queue(RabbitKeyOrderChildConstants.DEFAULT_DEAD_QUEUE);
    }
    @Bean
    public Binding orderChildDefaultDeadQueueBinding() {
        return BindingBuilder.bind(orderChildDefaultDeadQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.DEFAULT_DEAD_ROUTING_KEY);
    }


    /**
     * 新增
     */
    @Bean
    public Queue orderChildAddQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_ADD_QUEUE);
    }
    @Bean
    public Binding orderChildAddQueueBinding() {
        return BindingBuilder.bind(orderChildAddQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_ADD_ROUTING_KEY);
    }

    /**
     * 到达货源地
     */
    @Bean
    public Queue orderChildArriveSendAddressQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_ARRIVE_SEND_ADDRESS_QUEUE);
    }
    @Bean
    public Binding orderChildArriveSendAddressQueueBinding() {
        return BindingBuilder.bind(orderChildArriveSendAddressQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_ARRIVE_SEND_ADDRESS_ROUTING_KEY);
    }

    /**
     * 到达目的地
     */
    @Bean
    public Queue orderChildArriveReceiveAddressQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_ARRIVE_RECEIVE_ADDRESS_QUEUE);
    }
    @Bean
    public Binding orderChildArriveReceiveAddressQueueBinding() {
        return BindingBuilder.bind(orderChildArriveReceiveAddressQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_ARRIVE_RECEIVE_ADDRESS_ROUTING_KEY);
    }

    /**
     * 司机确认收货
     */
    @Bean
    public Queue orderChildDriverConfirmQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_DRIVER_CONFIRM_QUEUE);
    }
    @Bean
    public Binding orderChildDriverConfirmQueueBinding() {
        return BindingBuilder.bind(orderChildDriverConfirmQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_DRIVER_CONFIRM_ROUTING_KEY);
    }

    /**
     * 装车
     */
    @Bean
    public Queue orderChildLoadQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_LOAD_QUEUE);
    }
    @Bean
    public Binding orderChildLoadQueueBinding() {
        return BindingBuilder.bind(orderChildLoadQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_LOAD_ROUTING_KEY);
    }

    /**
     * 卸车
     */
    @Bean
    public Queue orderChildUnloadQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_UNLOAD_QUEUE);
    }
    @Bean
    public Binding orderChildUnloadQueueBinding() {
        return BindingBuilder.bind(orderChildUnloadQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_UNLOAD_ROUTING_KEY);
    }

    /**
     * 运单取消
     */
    @Bean
    public Queue orderChildCancelQueue() {
        return new Queue(RabbitKeyOrderChildConstants.ORDER_CHILD_CANCEL_QUEUE);
    }
    @Bean
    public Binding orderChildCancelQueueBinding() {
        return BindingBuilder.bind(orderChildCancelQueue()).to(orderChildDefaultExchange()).with(RabbitKeyOrderChildConstants.ORDER_CHILD_CANCEL_ROUTING_KEY);
    }

}
