package org.wcs.plugin.tcp.model;

import lombok.Getter;
import lombok.Setter;
import org.wcs.plugin.tcp.enums.SocketStatusEnum;

import java.net.Socket;
import java.time.LocalDateTime;

/**
 * Socket 数据项
 */
@Getter
@Setter
public class SocketDataItem {

    /**
     * SocketId
     */
    private String socketId;

    /**
         * Socket标记
     */
    private String socketTag;

    /**
     * Socket IP
     */
    private String socketIp;

    /**
     * Socket 端口
     */
    private int socketPort;

    /**
     * 心跳包内容
     */
    private String heartBeatString;

    /**
     * Socket
     */
    private Socket socket;

    /**
     * 自动重连
     */
    private boolean autoReconnect;

    /**
     * Socket 状态
     */
    private SocketStatusEnum socketStatus;

    /**
     * 最后收到消息时间
     */
    private LocalDateTime lastReceiveMessageTime;

    /**
     * 手动断开连接 ---- 手动断开这里是true
     */
    private boolean userDisConnected;

    /**
     * 构建开始
     * @return SocketDataItem
     */
    public static SocketDataItem buildStart() {
        SocketDataItem socketDataItem = new SocketDataItem();
        socketDataItem.setSocketStatus(SocketStatusEnum.CREATE);
        socketDataItem.setAutoReconnect(true);
        socketDataItem.setUserDisConnected(false);
        return socketDataItem;
    }

    /**
     * 设置SocketId
     * @param socketId SocketId
     * @return SocketDataItem
     */
    public SocketDataItem setSocketId(String socketId) {
        this.socketId = socketId;
        return this;
    }

    /**
     * 设置Socket IP
     * @param ip Socket IP
     * @return SocketDataItem
     */
    public SocketDataItem setIp(String ip) {
        this.socketIp = ip;
        return this;
    }

    /**
     * 端口
     * @param port 端口
     * @return SocketDataItem
     */
    public SocketDataItem setPort(int port) {
        this.socketPort = port;
        return this;
    }

    /**
     * 标记
     * @param tag 标记
     * @return SocketDataItem
     */
    public SocketDataItem setTag(String tag) {
        this.socketTag = tag;
        return this;
    }

    /**
     * 心跳包内容
     * @param heartBeatString 心跳包内容
     * @return SocketDataItem
     */
    public SocketDataItem setHeartBeatString(String heartBeatString) {
        this.heartBeatString = heartBeatString;
        return this;
    }

    /**
     * 自动重连
     * @param autoReconnect 自动重连
     * @return SocketDataItem
     */
    public SocketDataItem setAutoReconnect(boolean autoReconnect) {
        this.autoReconnect = autoReconnect;
        return this;
    }



    /**
     * 构建结束
     * @return SocketDataItem
     */
    public SocketDataItem buildEnd() {
        return this;
    }


    @Override
    public String toString() {
        return "SocketDataItem{" +
                "socketId='" + socketId + '\'' +
                ", socketTag='" + socketTag + '\'' +
                ", socketIp='" + socketIp + '\'' +
                ", socketPort=" + socketPort +
                ", heartBeatString='" + heartBeatString + '\'' +
                ", autoReconnect=" + autoReconnect +
                ", socketStatus=" + socketStatus +
                '}';
    }


}
