package cn.reghao.tnb.account.app.util;

import cn.reghao.jutil.jdk.serializer.JsonConverter;
import cn.reghao.tnb.message.api.dto.msg.LoginMessage;
import cn.reghao.tnb.message.api.dto.msg.VerifyMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @author reghao
 * @date 2024-04-19 14:38:30
 */
@Component
public class RabbitProducer {
    private final RabbitTemplate rabbitTemplate;

    public RabbitProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void sendVerifyMessage(VerifyMessage verifyMessage) {
        String routingKey = "tnb.message.account";
        String jsonPayload = JsonConverter.objectToJson(verifyMessage);
        rabbitTemplate.convertAndSend(routingKey, verifyMessage);
    }

    public void sendLoginMessage(LoginMessage loginMessage) {
        String routingKey = "tnb.message.account";
        String jsonPayload = JsonConverter.objectToJson(loginMessage);
        rabbitTemplate.convertAndSend(routingKey, jsonPayload);
    }
}
