package com.izouma.nineth.listener;

import com.izouma.nineth.event.OrderNotifyEvent;
import com.izouma.nineth.service.OrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
@RocketMQMessageListener(
        consumerGroup = "${general.order-notify-group}",
        topic = "${general.order-notify-topic}",
        consumeMode = ConsumeMode.ORDERLY)
@ConditionalOnProperty(value = "general.notify-server", havingValue = "true")
public class OrderNotifyListener implements RocketMQListener<OrderNotifyEvent> {
    private OrderService orderService;

    @Override
    public void onMessage(OrderNotifyEvent e) {
        orderService.notifyOrder(e.getOrderId(), e.getPayMethod(), e.getTransactionId());
    }
}
