package com.ym.mec.biz.dal.dto;

import com.ym.mec.biz.dal.enums.WebsocketTypeEnum;
import org.springframework.http.HttpStatus;

import java.util.HashMap;

/**
 * @Author Joburgess
 * @Date 2021/6/17 0017
 */
public class WebSocketInfo<T> {

    private Head header = new Head();

    private T body;

    public static class Head{
        private int status = HttpStatus.OK.value();
        private String commond = "";
        private WebsocketTypeEnum type;

        public Head() {
        }

        public Head(int status) {
            this.status = status;
        }

        public Head(String commond) {
            this.commond = commond;
        }

        public Head(String commond, WebsocketTypeEnum type) {
            this.commond = commond;
            this.type = type;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getCommond() {
            return commond;
        }

        public void setCommond(String commond) {
            this.commond = commond;
        }

        public WebsocketTypeEnum getType() {
            return type;
        }

        public void setType(WebsocketTypeEnum type) {
            this.type = type;
        }
    }

    public WebSocketInfo() {
    }

    public WebSocketInfo(Head header) {
        this.header = header;
    }

    public static WebSocketInfo success(){
        return new WebSocketInfo(new Head());
    }

    public static WebSocketInfo success(String commond){
        return new WebSocketInfo(new Head(commond));
    }

    public static WebSocketInfo success(String commond, String bodyKey, Object bodyValue){
        WebSocketInfo webSocketInfo = new WebSocketInfo(new Head(commond));
        webSocketInfo.setBody(new HashMap<String, Object>(){{put(bodyKey, bodyValue);}});
        return webSocketInfo;
    }

    public Head getHeader() {
        return header;
    }

    public void setHeader(Head header) {
        this.header = header;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }
}
