package com.app.feign.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 最终包装发送给微信服务器的消息对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BotMsg {

    /**
     * 消息类型
     */
    private String msgtype;

    private TextMsg text;

    private MarkdownMsg markdown;

    private ImageMsg image;

    private Map<String, List<ArticleMsg>> news;

    public BotMsg(TextMsg text) {
        this.text = text;
        this.msgtype = MsgType.TEXT;
    }

    public BotMsg(MarkdownMsg markdown) {
        this.markdown = markdown;
        this.msgtype = MsgType.MARKDOWN;
    }

    public BotMsg(ImageMsg imageMsg) {
        this.image = imageMsg;
        this.msgtype = MsgType.IMAGE;
    }

    public BotMsg(ArticleMsg articleMsg) {
        List<ArticleMsg> articleMsgList = new ArrayList<ArticleMsg>();
        articleMsgList.add(articleMsg);
        this.msgtype = MsgType.NEWS;
        this.news = new HashMap<String, List<ArticleMsg>>();
        this.news.put("articles", articleMsgList);
    }

    public BotMsg(List<ArticleMsg> articleMsgList) {
        this.msgtype = MsgType.NEWS;
        this.news = new HashMap<String, List<ArticleMsg>>();
        this.news.put("articles", articleMsgList);
    }

}
