package cn.com.ty.lift.ud.neety.protocol;

import org.apache.commons.lang3.StringUtils;
import org.msgpack.annotation.Message;

import lombok.Data;

/**
 * 自定义消息实体类
 * @author sKing
 * 2020年5月9日
 */
@Message
@Data
public class IMMessage {

    private String addr; // IP地址及端口
    private String cmd; // 命令类型[LOGIN]或者[SYSTEM]或者[LOGOUT]
    private long time; // 命令发送时间
    private int online; // 当前在线人数
    private String name; // 发送人
    private String avatarUrl; // 头像
    private String userId; // 用户id
    private String receiver; // 接收人
    private String msg; // 消息内容
    private Integer type; // 发送消息类型
    private String fromUser; // 当前用户id
    private String sessionid; // 房间号
    private int dataTable; // 消息来源1:问诊，2:出诊，3:附近的人

    public void setMsg(String msg) {
        this.msg = StringUtils.isNotBlank(msg) ?msg : null;
    }

    public IMMessage() {}

    public IMMessage(String cmd, long time, int online, String msg) {
        this.cmd = cmd;
        this.time = time;
        this.online = online;
        this.msg = msg;
    }

    public IMMessage(String cmd, long time, String sender, String content, String room) {
        this.cmd = cmd;
        this.time = time;
        this.name = sender;
        this.msg = content;
        this.sessionid = room;
    }

    public IMMessage(String cmd, long time, String sender) {
        this.cmd = cmd;
        this.time = time;
        this.name = sender;
    }

    public IMMessage(String cmd, String type, long time, String sender, String content, String headPic, String room) {
        this.cmd = cmd;
        this.time = time;
        this.name = sender;
        this.msg = content;
        this.avatarUrl = headPic;
        this.sessionid = room;
        this.type = StringUtils.isNotBlank(type) == true ? Integer.parseInt(type) : 1;
    }

}
