package cn.reghao.tnb.auth.app.config.rabbitmq;

import cn.reghao.jutil.jdk.serializer.JsonConverter;
import cn.reghao.tnb.auth.app.model.vo.RtmpPlay;
import cn.reghao.tnb.message.api.dto.msg.LoginMessage;
import cn.reghao.tnb.message.api.dto.msg.RtmpMessage;
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, jsonPayload);
    }

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

    public void sendRtmpMessage(RtmpPlay rtmpPlay) {
        String callType = rtmpPlay.getCall();
        String camName = rtmpPlay.getName();
        String clientId = rtmpPlay.getClientid();
        String clientAddress = rtmpPlay.getAddr();
        RtmpMessage rtmpMessage = new RtmpMessage(callType, camName, clientId, clientAddress);

        String routingKey = "tnb.message.account";
        String jsonPayload = JsonConverter.objectToJson(rtmpMessage);
        rabbitTemplate.convertAndSend(routingKey, jsonPayload);
    }
}
