package cn.reghao.tnb.message.app.service.notifier.ding;

import lombok.Data;

import java.util.Arrays;

/**
 * 钉钉消息
 *
 * @author reghao
 * @date 2019-10-24 15:00:28
 */
@Data
public class DingMsg {
    private Text text;
    private Markdown markdown;
    private String msgtype;
    private At at;

    /**
     * 文本消息
     * https://developers.dingtalk.com/document/app/custom-robot-access
     *
     * @param
     * @return
     * @date 2021-03-05 下午4:52
     */
    public DingMsg(Object content) {
        this.text = new Text(content);
        this.msgtype = MsgType.text.name();
        this.at = new At(true);
    }

    /**
     * markdown 消息
     *
     * @param
     * @return
     * @date 2021-03-05 下午4:52
     */
    public DingMsg(String title, String text) {
        this.markdown = new Markdown(title, text);
        this.msgtype = MsgType.markdown.name();
        this.at = new At(true);
    }

    static class Markdown {
        private String title;
        private String text;

        public Markdown(String title, String text) {
            this.title = title;
            this.text = text;
        }
    }

    static class Text {
        private Object content;

        public Text(Object content) {
            this.content = content;
        }
    }

    static class At {
        private boolean isAtAll;
        private String atMobiles;

        public At(boolean isAtAll) {
            this.isAtAll = isAtAll;
        }

        public At(String[] mobiles) {
            this.isAtAll = false;
            this.atMobiles = Arrays.toString(mobiles);
        }
    }

    enum MsgType {
        text, markdown
    }
}
