package com.xingxi.mq.consumer.order;

import com.xingxi.common.mq.constant.OrderMqKey;
import com.xingxi.common.mq.core.AbstractRabbitConsumer;
import com.google.common.collect.Lists;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class OrderCloseConsumer extends AbstractRabbitConsumer {
    @Bean(OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID)
    @Override
    protected List<Binding> getBindingList() {
        long xmTtl = 10 * 60 * 1000;
        return Lists.newArrayList(
                this.bindDelay(OrderMqKey.EDIT_EXCHANGE_DELAY,
                        OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID,
                        OrderMqKey.EDIT_ROUTE_DELAY_FOR_CREATED,
                        xmTtl));
    }

    @RabbitListener(queues = OrderMqKey.EDIT_QUEUE_DELAY_FOR_UNPAID)
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        this.convertMessage(message, channel);
    }

    @Override
    public boolean execute(String body, Channel channel, Message message) throws Exception {
        return true;
    }
}
