package com.its.op.dto.its.facility;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;

/**
 *  DTO Class
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("FcltSttsDto(시설물 상태정보)")
public class FcltSttsErrorDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("시설물 유형")
    @JsonProperty("fclt_type")
    private String fcltType;
    @ApiModelProperty("시설물 관리번호")
    @JsonProperty("fclt_nmbr")
    private String fcltNmbr;
    @ApiModelProperty("시설물 ID")
    @JsonProperty("fclt_id")
    private String fcltId;
    @ApiModelProperty("시설물 명칭")
    @JsonProperty("fclt_nm")
    private String fcltNm;

    @ApiModelProperty("통신상태코드")
    @JsonProperty("comm_stts_cd")
    private String commSttsCd;
    @ApiModelProperty("도어상태코드")
    @JsonProperty("door_stts_cd")
    private String doorSttsCd;
    @ApiModelProperty("함체온도")
    @JsonProperty("cbox_tmpr")
    private Integer cboxTmpr;
    @ApiModelProperty("발생시각")
    @JsonProperty("crtn_dt")
    private String crtnDt;

    @ApiModelProperty("통신상태코드설명")
    @JsonProperty("comm_stts_desc")
    private String commSttsDesc;
    @ApiModelProperty("도어상태코드설명")
    @JsonProperty("door_stts_desc")
    private String doorSttsDesc;
    @ApiModelProperty("함체온도이상여부설명")
    @JsonProperty("cbox_tmpr_desc")
    private String cboxTmprDesc;

    public void makeSttsDesc(String fcltType) {
        if      (StringUtils.equals("CMS0", this.commSttsCd)) this.commSttsDesc = "정상";
        else if (StringUtils.equals("CMS1", this.commSttsCd)) this.commSttsDesc = "통신두절";
        else if (StringUtils.equals("-",    this.commSttsCd)) this.commSttsDesc = "-";
        else                                                  this.commSttsDesc = "정보없음";

        if (fcltType.equals("CCTV")) {
            this.doorSttsCd = "CDS2";
            this.cboxTmpr = 255;
            this.cboxTmprDesc = "-";
            this.doorSttsDesc = "-";
            this.cboxTmprDesc = "-";
        }
        else {
            if (StringUtils.equals("CMS0", this.commSttsCd)) {
                if      (StringUtils.equals("CDS0", this.doorSttsCd)) this.doorSttsDesc = "닫힘";
                else if (StringUtils.equals("CDS1", this.doorSttsCd)) this.doorSttsDesc = "열림";
                else if (StringUtils.equals("-", this.doorSttsCd))    this.doorSttsDesc = "-";
                else                                                  this.doorSttsDesc = "정보없음";

                if (this.cboxTmpr > 40) {
                    this.cboxTmprDesc = "이상";
                }
                else {
                    this.cboxTmprDesc = "정상";
                }
            }
            else {
                this.cboxTmpr = 255;
                this.doorSttsDesc = "정보없음";
                this.cboxTmprDesc = "정보없음";
            }
        }
    }
}
