package com.ematou.wxservice.mp.message;

import com.ematou.wxservice.common.utils.XStreamTransformer;
import com.ematou.wxservice.common.xml.builder.ImageBuilder;
import com.ematou.wxservice.common.xml.builder.NewsBuilder;
import com.ematou.wxservice.common.xml.builder.TextBuilder;
import com.ematou.wxservice.common.xml.converter.XStreamCDataConverter;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;

import java.io.Serializable;

/**
 * 响应消息基类，没新增一种响应消息类型，都需要将其注册到XStreamTransformer类的Map中。
 * @author lhm
 * @version 1.0
 * 2021-05-11 14:51
 */
@XStreamAlias("xml")
public abstract class WeChatMpXmlOutMessage implements Serializable {

    private static final long serialVersionUID = -381382011286216263L;

    @XStreamAlias("ToUserName")
    @XStreamConverter(value = XStreamCDataConverter.class)
    protected String toUserName;

    @XStreamAlias("FromUserName")
    @XStreamConverter(value = XStreamCDataConverter.class)
    protected String fromUserName;

    @XStreamAlias("CreateTime")
    protected Long createTime;

    @XStreamAlias("MsgType")
    @XStreamConverter(value = XStreamCDataConverter.class)
    protected String msgType;

    @XStreamAlias("MsgId")
    protected Long msgId;

    /**
     * 获得文本消息builder
     */
    public static TextBuilder TEXT() {
        return new TextBuilder();
    }

    public static NewsBuilder NEWS() { return new NewsBuilder(); }
    public static ImageBuilder IMAGE() { return new ImageBuilder(); }

    public String toXml() {
        return XStreamTransformer.toXml((Class<WeChatMpXmlOutMessage>) this.getClass(), this);
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public Long getMsgId() {
        return msgId;
    }

    public void setMsgId(Long msgId) {
        this.msgId = msgId;
    }
}
