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

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 wangp
 * @date 2021/5/6 16:44
 * @description 查询短信模板审核状态
 * @since JDK 1.8
 */
@Configuration
public class QuerySmsTemplateCheckConfig {

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

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

    @Bean
    public Queue querySmsTemplateCheckQueue() {
        return new Queue(QueueTypeEnum.QUERY_SMS_TEMPLATE_CHECK.getQueue());
    }

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

    @Bean
    Binding querySmsTemplateCheckBinding(DirectExchange querySmsTemplateCheckDirect, Queue querySmsTemplateCheckQueue) {
        return BindingBuilder.bind(querySmsTemplateCheckQueue).to(querySmsTemplateCheckDirect).with(QueueTypeEnum.QUERY_SMS_TEMPLATE_CHECK.getQueueKey());
    }

    @Bean
    public Binding querySmsTemplateCheckTTLBinding(Queue querySmsTemplateCheckTTLQueue, DirectExchange querySmsTemplateCheckTTLDirect) {
        return BindingBuilder.bind(querySmsTemplateCheckTTLQueue).to(querySmsTemplateCheckTTLDirect)
                .with(QueueTTLTypeEnum.QUERY_SMS_TEMPLATE_CHECK_TTL.getQueueKey());
    }

}
