package thyyxxk.webserver.http.websocket.dto;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import thyyxxk.webserver.constants.Message;
import thyyxxk.webserver.utils.SocketMsg;

@Data
@NoArgsConstructor
public class WebSocketByUserCode {
    private String mode = "SINGLE";
    private String sid;
    private String msg;


    public WebSocketByUserCode(String sid) {
        this.sid = sid;
    }

    public WebSocketByUserCode(String sid, String msg) {
        this.sid = sid;
        this.msg = msg;
    }

    public void setMessage(JSONObject msgdata) {
        this.msg = msgdata.toJSONString();
    }

    public static WebSocketByUserCode create(String sid, String msg) {
        return new WebSocketByUserCode(sid, msg);
    }

    public static WebSocketByUserCode create(Message message, String sid, String msg) {
        return new WebSocketByUserCode(sid, SocketMsg.socketVo(message, msg));
    }

}
