package net.northking.cctp.upperComputer.driver.harmony.hdc;

/**
 * 一个接入到上位机的HDC协议设备
 */
public class HDCDevice {
    /**
     * 设备连接key，用于区分每一个设备，不同设备间唯一
     */
    private final String connectKey;

    /**
     * 连接方式
     */
    private final HDCConnectType connectType;

    /**
     * 连接状态
     */
    private HDCConnectStatus connectStatus;

    /**
     * 连接位置
     */
    private final String location;

    public HDCDevice(String connectKey, HDCConnectType connectType, HDCConnectStatus connectStatus, String location) {
        this.connectKey = connectKey;
        this.connectType = connectType;
        this.connectStatus = connectStatus;
        this.location = location;
    }

    public String getConnectKey() {
        return connectKey;
    }

    public HDCConnectType getConnectType() {
        return connectType;
    }

    public HDCConnectStatus getConnectStatus() {
        return connectStatus;
    }

    public void setConnectStatus(HDCConnectStatus connectStatus) {
        this.connectStatus = connectStatus;
    }

    public String getLocation() {
        return location;
    }

    /**
     * 获得连接协议
     *
     * @return 协议名称
     */
    public String getProtocol() {
        return "hdc";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        HDCDevice hdcDevice = (HDCDevice) o;
        return connectKey.equals(hdcDevice.connectKey) && connectType == hdcDevice.connectType && connectStatus == hdcDevice.connectStatus && location.equals(hdcDevice.location);
    }

    @Override
    public int hashCode() {
        int result = connectKey.hashCode();
        result = 31 * result + connectType.hashCode();
        result = 31 * result + connectStatus.hashCode();
        result = 31 * result + location.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "HDCDevice{" +
                "connectKey='" + connectKey + '\'' +
                ", connectType=" + connectType +
                ", connectStatus=" + connectStatus +
                ", location='" + location + '\'' +
                '}';
    }
}
