package net.northking.cctp.upperComputer.webSocket.entity;

public class CmdResponse {

    private String cmd;

    private String serial;

    private boolean success;

    private String message;

    private String requestId;

    private boolean finish;

    private Object data;

    public String getCmd() {
        return cmd;
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public static CmdResponse buildForInitiative(String cmd){
        CmdResponse responseBody = new CmdResponse();
        responseBody.setCmd(cmd);
        return responseBody;
    }

    public static CmdResponse build(CmdRequest requestBody){
        CmdResponse responseBody = new CmdResponse();
        responseBody.setCmd(requestBody.getCmd());
        responseBody.setSerial(requestBody.getSerial());
        responseBody.setRequestId(requestBody.getRequestId());
        return responseBody;
    }

    public CmdResponse withSerial(String serial){
        this.setSerial(serial);
        return this;
    }

    public CmdResponse success(){
        this.setSuccess(true);
        this.setMessage("指令执行成功");
        return this;
    }

    public CmdResponse success(Object data){
        this.setData(data);
        return success();
    }

    public CmdResponse finished(){
        this.setFinish(true);
        return success();
    }

    public CmdResponse continuous(){
        this.setFinish(false);
        return success();
    }

    public CmdResponse withData(Object data){
        this.setData(data);
        return this;
    }

    public CmdResponse fail(){
        this.setSuccess(false);
        this.setMessage("指令执行失败");
        return this;
    }

    public CmdResponse fail(String message){
        this.setSuccess(false);
        this.setMessage(message);
        return this;
    }

    public CmdResponse withMessage(String message){
        this.setMessage(message);
        return this;
    }

    public Object getData() {
        return data;
    }
}
