package com.tsi.comm.server.dto.mongodb;

import com.tsi.comm.server.dto.TsiCvimAbnormal;
import com.tsi.comm.server.dto.TsiCvimControl;
import com.tsi.comm.server.dto.TsiCvimStatus;
import com.tsi.common.utils.StringUtils;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
//import org.springframework.data.annotation.Id;
//import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Getter
@ToString
//@Document(collection = "tb_tcs_node_status")
public class TcsNodeStatus {

//    @Id
    private final Long _id;
    private final Long nodeId;
    private final boolean isConnect;
    private final String collectTime;
    private final String tscDateTime;
    private final int cycleElapsedTime;
    private final TsiCvimControl tscControlInfo;
    private final TsiCvimAbnormal tscAbnormalInfo;
    private final int signalStatusInfoCount;
    private final List<TsiCvimStatus> signalStatusInfos;

    @Builder
    public TcsNodeStatus(Long _id,
                         Long nodeId,
                         boolean isConnect,
                         String collectTime,
                         String tscDateTime,
                         int cycleElapsedTime,
                         TsiCvimControl tscControlInfo,
                         TsiCvimAbnormal tscAbnormalInfo,
                         int signalStatusInfoCount,
                         List<TsiCvimStatus> signalStatusInfos) {
        this._id = _id;
        this.nodeId = nodeId;
        this.isConnect = isConnect;
        this.collectTime = collectTime;
        this.tscDateTime = tscDateTime;
        this.cycleElapsedTime = cycleElapsedTime;
        this.tscControlInfo = tscControlInfo;
        this.tscAbnormalInfo = tscAbnormalInfo;
        this.signalStatusInfoCount = signalStatusInfoCount;
        this.signalStatusInfos = signalStatusInfos;
    }

    private String toValue(String connect) {
        return this.nodeId+","+connect+","+this.collectTime+","+this.tscDateTime+","+this.cycleElapsedTime+","+this.signalStatusInfoCount;
    }

    public String toDataString() {
        String connect = StringUtils.getString(this.isConnect);
        if (this.isConnect) {
            String statusValue = "";
            for (TsiCvimStatus status: this.signalStatusInfos) {
                statusValue = statusValue + status.toDataString() + "|";
            }

            return    toValue(connect)
                    + "^"
                    + this.tscControlInfo.toDataString()
                    + "^"
                    + this.tscAbnormalInfo.toDataString()
                    + "^"
                    + statusValue;
        }
        return this.nodeId+","+connect;
    }
}
