package com.erp.mq.producer;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 订单消息生产者
 * 负责发送订单相关的消息
 */
@Slf4j
@Component
public class OrderMessageProducer extends BaseRocketMQProducer {

    @Value("${erp.rocketmq.topics.order}")
    private String orderTopic;

    public static final String TAGS_CREATE = "create";
    public static final String TAGS_UPDATE = "update";
    public static final String TAGS_CANCEL = "cancel";
    public static final String TAGS_PAY = "pay";
    public static final String TAGS_SHIP = "ship";
    public static final String TAGS_DELIVER = "deliver";

    @Override
    protected String getTopic() {
        return orderTopic;
    }

    @Override
    protected String getProducerGroup() {
        return "erp-order-producer-group";
    }

    /**
     * 发送订单创建消息
     */
    public void sendOrderCreated(OrderMessage orderMessage) {
        log.info("发送订单创建消息 - OrderId: {}", orderMessage.getOrderId());
        sendMessage(orderMessage, TAGS_CREATE, orderMessage.getOrderId());
    }

    /**
     * 发送订单支付消息
     */
    public void sendOrderPaid(OrderMessage orderMessage) {
        log.info("发送订单支付消息 - OrderId: {}", orderMessage.getOrderId());
        sendMessage(orderMessage, TAGS_PAY, orderMessage.getOrderId());
    }

    /**
     * 发送订单发货消息
     */
    public void sendOrderShipped(OrderMessage orderMessage) {
        log.info("发送订单发货消息 - OrderId: {}", orderMessage.getOrderId());
        sendMessage(orderMessage, TAGS_SHIP, orderMessage.getOrderId());
    }

    /**
     * 发送订单取消消息
     */
    public void sendOrderCancelled(OrderMessage orderMessage) {
        log.info("发送订单取消消息 - OrderId: {}", orderMessage.getOrderId());
        sendMessage(orderMessage, TAGS_CANCEL, orderMessage.getOrderId());
    }

    @Data
    public static class OrderMessage {
        private String orderId;
        private String customerId;
        private Double totalAmount;
        private String status;
        private String paymentMethod;
        private Long timestamp;
    }
}
