package com.jpsoft.shinestar.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

@Configuration
public class RabbitmqConfig {
    @Bean
    public Queue importImageQueue() {
        return new Queue("importImageQueue",true);  //true 是否持久
    }

    @Bean
    public Queue syncWorkerAttendenceQueue() {
        return new Queue("syncWorkerAttendenceQueue",true);  //true 是否持久
    }

    @Bean
    DirectExchange importImageExchange() {
        return new DirectExchange("importImageExchange");
    }

    @Bean
    Binding bindingImportImageDirect() {
        return BindingBuilder.bind(importImageQueue()).to(importImageExchange()).with("importImage");
    }

    @Bean
    Binding bindingSyncWorkerAttendenceDirect() {
        return BindingBuilder.bind(syncWorkerAttendenceQueue()).to(importImageExchange()).with("syncWorkerAttendence");
    }

    /**
     * 删除设备中图片队列
     * @return
     */
    @Bean
    public Queue removeImageQueue() {
        return new Queue("removeImageQueue", true);
    }

    @Bean
    DirectExchange removeImageExchange() {
        return new DirectExchange("removeImageExchange");
    }

    @Bean
    Binding bindingRemoveImageDirect() {
        return BindingBuilder.bind(removeImageQueue()).to(removeImageExchange()).with("removeImage");
    }

    /**
     * 人员打卡通知队列
     * @return
     */
    @Bean
    public Queue personNotificationQueue(){
        return new Queue("personNotificationQueue", true);
    }

    @Bean
    DirectExchange personNotificationExchange() {
        return new DirectExchange("personNotificationExchange");
    }

    @Bean
    public Binding personNotificationBinding(){
        return BindingBuilder
                .bind(personNotificationQueue())
                .to(personNotificationExchange())
                .with("personNotification");
    }

    @Bean
    public Queue personGuestRecordQueue(){
        return new Queue("personGuestRecordQueue", true);
    }

    @Bean
    public Queue schoolMessageNoticeQueue() { return new Queue("schoolMessageNoticeQueue", true);}

    @Bean
    public Queue jpMedicationQueue() {
        Queue queue = new Queue("jpMedicationQueue", true);
        return queue;
    }

    @Bean
    public CustomExchange jpMedicationDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange("jpMedicationDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding jpMedicationBinding() {
        return BindingBuilder.bind(jpMedicationQueue())
                .to(jpMedicationDelayExchange())
                .with("submit").noargs();
    }


    /**
     * 请假修改工作状态
     * @return
     */
    @Bean
    public Queue requestForLeaveQueue() {
        Queue queue = new Queue("requestForLeaveQueue", true);
        return queue;
    }

    @Bean
    public CustomExchange requestForLeaveDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("requestForLeaveDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding requestForLeaveBinding() {
        return BindingBuilder.bind(requestForLeaveQueue())
                .to(requestForLeaveDelayExchange())
                .with("submit").noargs();
    }


    /**
     * 外出出差修改人员工作状态
     * @return
     */
    @Bean
    public Queue businessOutQueue() {
        Queue queue = new Queue("businessOutQueue", true);
        return queue;
    }

    @Bean
    public CustomExchange businessOutDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange("businessOutDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding businessOutBinding() {
        return BindingBuilder.bind(businessOutQueue())
                .to(businessOutDelayExchange())
                .with("businessOutSubmit").noargs();
    }


    /**
     * 年假修改人员工作状态
     * @return
     */
    @Bean
    public Queue yearRequestForLeaveQueue() {
        Queue queue = new Queue("yearRequestForLeaveQueue", true);
        return queue;
    }

    @Bean
    public CustomExchange yearRequestForLeaveDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange("yearRequestForLeaveDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding yearRequestForLeaveBinding() {
        return BindingBuilder.bind(yearRequestForLeaveQueue())
                .to(yearRequestForLeaveDelayExchange())
                .with("yearRequestForLeaveSubmit").noargs();
    }



    /**
     * 订单30分钟不支付的延时队列
     * @return
     */
    @Bean
    public Queue orderQueue() { return new Queue("orderQueue", true);}


    @Bean
    public CustomExchange orderDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange("orderDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(orderQueue())
                .to(orderDelayExchange())
                .with("order").noargs();
    }


    /**
     * 删除设备中访客记录队列
     * @return
     */
    @Bean
    public Queue personGuestQueue() {
        Queue queue = new Queue("removePersonGuestQueue", true);
        return queue;
    }

    @Bean
    CustomExchange personGuestExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("removePersonGuestExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    Binding bindingRemovePersonGuestDirect() {
        return BindingBuilder.bind(personGuestQueue()).to(personGuestExchange()).with("removePersonGuest").noargs();
    }

    /**
     * 同步手表收据
     * @return
     */
    @Bean
    public Queue syncWatchInfoQueue() {
        Queue queue = new Queue("syncWatchInfoQueue", true);

        return queue;
    }

    /**
     * 手表报警队列
     * @return
     */
    @Bean
    public Queue watchWarningQueue() {
        Queue queue = new Queue("watchWarningQueue", true);

        return queue;
    }

    /**
     * 健康监管数据队列
     * @return
     */
    @Bean
    public Queue companySuperviseQueue() {
        Queue queue = new Queue("companySuperviseQueue", true);

        return queue;
    }

    @Bean
    public Queue insertPersonInfoSuperviseQueue() {
        Queue queue = new Queue("insertPersonInfoSuperviseQueue", true);

        return queue;
    }


    /**
     * 删除设备中访客记录队列
     * @return
     */
    @Bean
    public Queue updateWorkStatusQueue() {
        Queue queue = new Queue("updateWorkStatusQueue", true);
        return queue;
    }

    @Bean
    CustomExchange updateWorkStatusExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("updateWorkStatusExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    Binding bindingUpdateWorkStatusDirect() {
        return BindingBuilder.bind(updateWorkStatusQueue()).to(updateWorkStatusExchange()).with("updateWorkStatus").noargs();
    }


    /**
     * 发送到期未支付的模板消息
     * @return
     */
    @Bean
    public Queue billPushQueue() {
        Queue queue = new Queue("billPushQueue", true);
        return queue;
    }

    @Bean
    CustomExchange billPushDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("billPushDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    Binding bindingBillPushDirect() {
        return BindingBuilder.bind(billPushQueue()).to(billPushDelayExchange()).with("billPushSubmit").noargs();
    }

    @Bean
    public Queue workerHealthyReportNoticeQueue() {
        return new Queue("workerHealthyReportNoticeQueue", true);
    }

    @Bean
    RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
    }

    /**
     * 设备交换机
     * @return
     */
    @Bean
    protected DirectExchange deviceExchange(){
        return (DirectExchange)ExchangeBuilder
                .directExchange("deviceExchange")
                .durable(true)
                .build();
    }

    @Bean
    public Queue updatePersonAttendanceQueue() {
        Queue queue = new Queue("updatePersonAttendanceQueue", true);

        return queue;
    }




    /**
     * 测试队列
     * @return
     */
    @Bean
    public Queue testYearRequestForLeaveQueue() {
        Queue queue = new Queue("testYearRequestForLeaveQueue", true);
        return queue;
    }

    @Bean
    public CustomExchange testYearRequestForLeaveDelayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");

        return new CustomExchange("testYearRequestForLeaveDelayExchange", "x-delayed-message",true, false,args);
    }

    @Bean
    public Binding testYearRequestForLeaveBinding() {
        return BindingBuilder.bind(testYearRequestForLeaveQueue())
                .to(testYearRequestForLeaveDelayExchange())
                .with("submit").noargs();
    }
}
