package com.fzm.mall.server.admin.mq.config.order_center;

import com.fzm.mall.server.admin.mq.enums.QueueTTLTypeEnum;
import com.fzm.mall.server.admin.mq.enums.QueueTypeEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wulixian
 * @description 发行货币
 * @date 2021/04/16  11:28
 */
@Configuration
public class WithdrawConfig {

    @Bean
    DirectExchange orderRefundCoinsDirect() {
        return (DirectExchange) ExchangeBuilder.directExchange(QueueTypeEnum.ORDER_REFUND_COINS.getExchange())
                .durable(true).build();
    }

    @Bean
    DirectExchange orderRefundCoinsTTLDirect() {
        return (DirectExchange) ExchangeBuilder.directExchange(QueueTTLTypeEnum.ORDER_REFUND_COINS_TTL.getExchange())
                .durable(true).build();
    }

    @Bean
    public Queue orderRefundCoinsQueue() {
        return new Queue(QueueTypeEnum.ORDER_REFUND_COINS.getQueue());
    }

    @Bean
    public Queue orderRefundCoinsTTLQueue() {
        return QueueBuilder.durable(QueueTTLTypeEnum.ORDER_REFUND_COINS_TTL.getQueue())
                // 配置到期后转发的交换
                .withArgument("x-dead-letter-exchange", QueueTypeEnum.ORDER_REFUND_COINS.getExchange())
                // 配置到期后转发的路由键
                .withArgument("x-dead-letter-routing-key", QueueTypeEnum.ORDER_REFUND_COINS.getQueueKey()).build();
    }

    @Bean
    Binding orderRefundCoinsBinding(DirectExchange orderRefundCoinsDirect, Queue orderRefundCoinsQueue) {
        return BindingBuilder.bind(orderRefundCoinsQueue).to(orderRefundCoinsDirect).with(QueueTypeEnum.ORDER_REFUND_COINS.getQueueKey());
    }

    @Bean
    public Binding orderRefundCoinsTTLBinding(Queue orderRefundCoinsTTLQueue, DirectExchange orderRefundCoinsTTLDirect) {
        return BindingBuilder.bind(orderRefundCoinsTTLQueue).to(orderRefundCoinsTTLDirect)
                .with(QueueTTLTypeEnum.ORDER_REFUND_COINS_TTL.getQueueKey());
    }

}
