package cn.reghao.tnb.message.app.model.msg;

import cn.reghao.jutil.jdk.converter.DateTimeConverter;
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 cn.reghao.tnb.message.app.service.notifier.ding.DingMsg;
import lombok.Getter;

/**
 * @author reghao
 * @date 2025-10-13 15:31:48
 */
@Getter
public class DingMsgUtil {
    public static DingMsg getDingMsg(RtmpMessage rtmpMessage) {
        String title = "RTMP 通知";
        StringBuilder sb = new StringBuilder();
        sb.append("# RTMP 通知").append(System.lineSeparator());
        sb.append("### RTMP 事件: ").append(rtmpMessage.getCallType()).append(System.lineSeparator());
        sb.append("### 摄像头: ").append(rtmpMessage.getAppName()).append(System.lineSeparator());
        sb.append("### 客户 ID: ").append(rtmpMessage.getClientId()).append(System.lineSeparator());
        sb.append("### 客户 IP: ").append(rtmpMessage.getClientAddress()).append(System.lineSeparator());
        sb.append("### 时间: ").append(DateTimeConverter.format(rtmpMessage.getTimestamp()));
        String text = sb.toString();
        return new DingMsg(title, text);
    }

    public static DingMsg getDingMsg(VerifyMessage verifyMessage) {
        String title = "验证码通知";
        StringBuilder sb = new StringBuilder();
        sb.append("# 验证码通知").append(System.lineSeparator());
        sb.append("### 用户: ").append(verifyMessage.getReceiver()).append(System.lineSeparator());
        sb.append("### 标题: ").append(verifyMessage.getTitle()).append(System.lineSeparator());
        sb.append("### 内容: ").append(verifyMessage.getContent()).append(System.lineSeparator());
        sb.append("### 时间: ").append(DateTimeConverter.format(verifyMessage.getTimestamp()));
        String text = sb.toString();
        return new DingMsg(title, text);
    }

    public static DingMsg getDingMsg(LoginMessage loginMessage) {
        String content = String.format("您的帐号在 %s 通过客户端 %s 登入, 登入 IP 为 %s",
                loginMessage.getLoginAt(), loginMessage.getUserAgent(), loginMessage.getPublicIp());
        String title = "登入通知";
        StringBuilder sb = new StringBuilder();
        sb.append("# 验证码通知").append(System.lineSeparator());
        sb.append("### 用户: ").append(loginMessage.getReceiver()).append(System.lineSeparator());
        sb.append("### 标题: ").append(loginMessage.getTitle()).append(System.lineSeparator());
        sb.append("### 内容: ").append(content).append(System.lineSeparator());
        sb.append("### 时间: ").append(DateTimeConverter.format(loginMessage.getTimestamp()));
        String text = sb.toString();
        return new DingMsg(title, text);
    }
}
