package com.its.api.its.model.entity.incident;

import com.its.api.its.global.CodeManager;
import com.its.api.its.model.dto.incident.TbIncdOcrrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * 돌발상황 발생 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("돌발상황 발생")
@Entity
@Table(name = "TB_INCD_OCRR")
public class TbIncdOcrr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("돌발상황 발생 ID")  // N VARCHAR(12)
    @Id
    @Column(name = "INCD_OCRR_ID", nullable = false, length = 12)
    private String incdOcrrId;

    @ApiModelProperty("등록 일시")  // Y VARCHAR(14)
    @Column(name = "RGST_DT", length = 14)
    private String rgstDt;

    @ApiModelProperty("돌발상황 원본 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_ORGN_CD", length = 7)
    private String incdOrgnCd;

    @ApiModelProperty("발생 위치 명")  // Y VARCHAR(100)
    @Column(name = "OCRR_LCTN_NM", length = 100)
    private String ocrrLctnNm;

    @ApiModelProperty("X 좌표")  // Y NUMBER(11,8)
    @Column(name = "X_CRDN", columnDefinition = "NUMBER", length = 11, precision = 8)
    private Double xCrdn;

    @ApiModelProperty("Y 좌표")  // Y NUMBER(10,8)
    @Column(name = "Y_CRDN", columnDefinition = "NUMBER", length = 10, precision = 8)
    private Double yCrdn;

    @ApiModelProperty("돌발상황 설명")  // Y VARCHAR(600)
    @Column(name = "INCD_EXPL", length = 600)
    private String incdExpl;

    @ApiModelProperty("소통 등급 코드")  // Y VARCHAR(7)
    @Column(name = "CMTR_GRAD_CD", length = 7)
    private String cmtrGradCd;

    @ApiModelProperty("제보자 명")  // Y VARCHAR(20)
    @Column(name = "IFMR_NM", length = 20)
    private String ifmrNm;

    @ApiModelProperty("돌발상황 확인 방법 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_CNFM_MTHD_CD", length = 7)
    private String incdCnfmMthdCd;

    @ApiModelProperty("돌발상황 확인 일시")  // Y VARCHAR(14)
    @Column(name = "INCD_CNFM_DT", length = 14)
    private String incdCnfmDt;

    @ApiModelProperty("돌발상황 시작 일시")  // Y VARCHAR(14)
    @Column(name = "INCD_STRT_DT", length = 14)
    private String incdStrtDt;

    @ApiModelProperty("돌발상황 종료 예정 일시")  // Y VARCHAR(14)
    @Column(name = "INCD_END_PRAR_DT", length = 14)
    private String incdEndPrarDt;

    @ApiModelProperty("돌발상황 유형 분류 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_TYPE_CLSF_CD", length = 7)
    private String incdTypeClsfCd;

    @ApiModelProperty("돌발상황 유형 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_TYPE_CD", length = 7)
    private String incdTypeCd;

    @ApiModelProperty("돌발상황 제목")  // Y VARCHAR(400)
    @Column(name = "INCD_TITL", length = 400)
    private String incdTitl;

    @ApiModelProperty("돌발상황 심각도 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_SERN_CD", length = 7)
    private String incdSernCd;

    @ApiModelProperty("지체 길이")  // Y NUMBER(5)
    @Column(name = "DELY_LNGT", columnDefinition = "NUMBER", length = 5)
    private Integer delyLngt;

    @ApiModelProperty("돌발상황 길이")  // Y NUMBER(5)
    @Column(name = "INCD_LNGT", columnDefinition = "NUMBER", length = 5)
    private Integer incdLngt;

    @ApiModelProperty("돌발상황 발생 차로")  // Y VARCHAR(6)
    @Column(name = "INCD_OCRR_LANE", length = 6)
    private String incdOcrrLane;

    @ApiModelProperty("돌발상황 차단 차로")  // Y VARCHAR(6)
    @Column(name = "INCD_CLSR_LANE", length = 6)
    private String incdClsrLane;

    @ApiModelProperty("통행 제한 유형 코드")  // Y VARCHAR(7)
    @Column(name = "TRVL_LMNT_TYPE_CD", length = 7)
    private String trvlLmntTypeCd;

    @ApiModelProperty("고장 차량 여부")  // Y CHAR(1)
    @Column(name = "TRUB_VHCL_YN", columnDefinition = "CHAR", length = 1)
    private String trubVhclYn;

    @ApiModelProperty("낙하물 여부")  // Y CHAR(1)
    @Column(name = "FALT_YN", columnDefinition = "CHAR", length = 1)
    private String faltYn;

    @ApiModelProperty("화재위험물 여부")  // Y CHAR(1)
    @Column(name = "FRWT_YN", columnDefinition = "CHAR", length = 1)
    private String frwtYn;

    @ApiModelProperty("UTIS 연계 여부")  // Y CHAR(1)
    @Column(name = "UTIS_CNCT_YN", columnDefinition = "CHAR", length = 1)
    private String utisCnctYn;

    @ApiModelProperty("소형 차량 대수")  // Y NUMBER(5)
    @Column(name = "SMLT_VHCL_UNUM", columnDefinition = "NUMBER", length = 5)
    private Integer smltVhclUnum;

    @ApiModelProperty("중대형 차량 대수")  // Y NUMBER(5)
    @Column(name = "MDLT_VHCL_UNUM", columnDefinition = "NUMBER", length = 5)
    private Integer mdltVhclUnum;

    @ApiModelProperty("부상자 인원수")  // Y NUMBER(4)
    @Column(name = "INJR_PNUM", columnDefinition = "NUMBER", length = 4)
    private Integer injrPnum;

    @ApiModelProperty("사망자 인원수")  // Y NUMBER(4)
    @Column(name = "FTLT_PNUM", columnDefinition = "NUMBER", length = 4)
    private Integer ftltPnum;

    @ApiModelProperty("기상 코드")  // Y VARCHAR(7)
    @Column(name = "WTHR_CD", length = 7)
    private String wthrCd;

    @ApiModelProperty("대응 수준 코드")  // Y VARCHAR(7)
    @Column(name = "RESP_LVL_CD", length = 7)
    private String respLvlCd;

    @ApiModelProperty("VMS 표출 여부")  // Y CHAR(1)
    @Column(name = "VMS_DSPL_YN", columnDefinition = "CHAR", length = 1)
    private String vmsDsplYn;

    @ApiModelProperty("돌발상황 진행 단계 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_PRGR_STEP_CD", length = 7)
    private String incdPrgrStepCd;

    @ApiModelProperty("돌발상황 종료 확인 방법 코드")  // Y VARCHAR(7)
    @Column(name = "INCD_END_CNFM_MTHD_CD", length = 7)
    private String incdEndCnfmMthdCd;

    @ApiModelProperty("돌발상황 종료 일시")  // Y VARCHAR(14)
    @Column(name = "INCD_END_DT", length = 14)
    private String incdEndDt;

    @ApiModelProperty("출동 장비 내용")  // Y VARCHAR(400)
    @Column(name = "MBLZ_EQPM_CONT", length = 400)
    private String mblzEqpmCont;

    @ApiModelProperty("출동 인원수")  // Y NUMBER(5)
    @Column(name = "MBLZ_PNUM", columnDefinition = "NUMBER", length = 5)
    private Integer mblzPnum;

    @ApiModelProperty("복구 내용")  // Y VARCHAR(400)
    @Column(name = "RECR_CONT", length = 400)
    private String recrCont;

    @ApiModelProperty("복구 기간")  // Y NUMBER(5)
    @Column(name = "RECR_PERD", columnDefinition = "NUMBER", length = 5)
    private Integer recrPerd;

    @ApiModelProperty("링크ID")  // Y NUMBER(10)
    @Column(name = "LINK_ID", columnDefinition = "NUMBER", length = 10)
    private Long linkId;

    public void setMisInfo() {
        this.incdPrgrStepCd = CodeManager.INCD_PRGR_STEP_ISS4;
    }
    public TbIncdOcrrDto toDto() {
        TbIncdOcrrDto dto = TbIncdOcrrDto.builder()
                .incdOcrrId(this.incdOcrrId)
                .rgstDt(this.rgstDt)
                .incdOrgnCd(this.incdOrgnCd)
                .ocrrLctnNm(this.ocrrLctnNm)
                .xCrdn(this.xCrdn)
                .yCrdn(this.yCrdn)
                .incdExpl(this.incdExpl)
                .cmtrGradCd(this.cmtrGradCd)
                .ifmrNm(this.ifmrNm)
                .incdCnfmMthdCd(this.incdCnfmMthdCd)
                .incdCnfmDt(this.incdCnfmDt)
                .incdStrtDt(this.incdStrtDt)
                .incdEndPrarDt(this.incdEndPrarDt)
                .incdTypeClsfCd(this.incdTypeClsfCd)
                .incdTypeCd(this.incdTypeCd)
                .incdTitl(this.incdTitl)
                .incdSernCd(this.incdSernCd)
                .delyLngt(this.delyLngt)
                .incdLngt(this.incdLngt)
                .incdOcrrLane(this.incdOcrrLane)
                .incdClsrLane(this.incdClsrLane)
                .trvlLmntTypeCd(this.trvlLmntTypeCd)
                .trubVhclYn(this.trubVhclYn)
                .faltYn(this.faltYn)
                .frwtYn(this.frwtYn)
                .utisCnctYn(this.utisCnctYn)
                .smltVhclUnum(this.smltVhclUnum)
                .mdltVhclUnum(this.mdltVhclUnum)
                .injrPnum(this.injrPnum)
                .ftltPnum(this.ftltPnum)
                .wthrCd(this.wthrCd)
                .respLvlCd(this.respLvlCd)
                .vmsDsplYn(this.vmsDsplYn)
                .incdPrgrStepCd(this.incdPrgrStepCd)
                .incdEndCnfmMthdCd(this.incdEndCnfmMthdCd)
                .incdEndDt(this.incdEndDt)
                .mblzEqpmCont(this.mblzEqpmCont)
                .mblzPnum(this.mblzPnum)
                .recrCont(this.recrCont)
                .recrPerd(this.recrPerd)
                .linkId(this.linkId)
                .build();

        dto.setIncdOrgnDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_IST, this.incdOrgnCd));
        dto.setCmtrGradDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_LTCU, this.cmtrGradCd));
        dto.setIncdCnfmMthdDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_ICM, this.incdCnfmMthdCd));
        dto.setIncdTypeClsfDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_IDTU, this.incdTypeClsfCd));
        if ("1".equals(this.incdTypeClsfCd)) {
            dto.setIncdTypeDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_ACTU, this.incdTypeCd));
        }
        else if ("2".equals(this.incdTypeClsfCd)) {
            dto.setIncdTypeDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_CRTU, this.incdTypeCd));
        }
        else if ("3".equals(this.incdTypeClsfCd)) {
            dto.setIncdTypeDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_EVTU, this.incdTypeCd));
        }
        else {
            dto.setIncdTypeDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_WETU, this.incdTypeCd));
        }

        dto.setIncdSernDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_SRLU, this.incdSernCd));
        dto.setTrvlLmntTypeDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_PRTU, this.trvlLmntTypeCd));
        dto.setTrubVhclDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_PRTU, this.trvlLmntTypeCd));

        dto.setRespLvlDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_RSL, this.respLvlCd));
        dto.setIncdPrgrStepDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_ISS, this.incdPrgrStepCd));
        dto.setIncdEndCnfmMthdDesc(CodeManager.getCodeDesc(CodeManager.INCD_CODE_ICM, this.incdEndCnfmMthdCd));

        return dto;
    }

    public TbIncdOcrr(String incdOcrrId) {
        this.incdOcrrId = incdOcrrId;
    }

    public void updateInfo(TbIncdOcrrDto.TbIncdOcrrUpdReq req) {
        this.rgstDt = req.getRgstDt();
        this.incdOrgnCd = req.getIncdOrgnCd();
        this.ocrrLctnNm = req.getOcrrLctnNm();
        this.xCrdn = req.getXCrdn();
        this.yCrdn = req.getYCrdn();
        this.incdExpl = req.getIncdExpl();
        this.cmtrGradCd = req.getCmtrGradCd();
        this.ifmrNm = req.getIfmrNm();
        this.incdCnfmMthdCd = req.getIncdCnfmMthdCd();
        this.incdCnfmDt = req.getIncdCnfmDt();
        this.incdStrtDt = req.getIncdStrtDt();
        this.incdEndPrarDt = req.getIncdEndPrarDt();
        this.incdTypeClsfCd = req.getIncdTypeClsfCd();
        this.incdTypeCd = req.getIncdTypeCd();
        this.incdTitl = req.getIncdTitl();
        this.incdSernCd = req.getIncdSernCd();
        this.delyLngt = req.getDelyLngt();
        this.incdLngt = req.getIncdLngt();
        this.incdOcrrLane = req.getIncdOcrrLane();
        this.incdClsrLane = req.getIncdClsrLane();
        this.trvlLmntTypeCd = req.getTrvlLmntTypeCd();
        this.trubVhclYn = req.getTrubVhclYn();
        this.faltYn = req.getFaltYn();
        this.frwtYn = req.getFrwtYn();
        this.utisCnctYn = req.getUtisCnctYn();
        this.smltVhclUnum = req.getSmltVhclUnum();
        this.mdltVhclUnum = req.getMdltVhclUnum();
        this.injrPnum = req.getInjrPnum();
        this.ftltPnum = req.getFtltPnum();
        this.wthrCd = req.getWthrCd();
        this.respLvlCd = req.getRespLvlCd();
        this.vmsDsplYn = req.getVmsDsplYn();
        this.incdPrgrStepCd = req.getIncdPrgrStepCd();
        this.incdEndCnfmMthdCd = req.getIncdEndCnfmMthdCd();
        this.incdEndDt = req.getIncdEndDt();
        this.mblzEqpmCont = req.getMblzEqpmCont();
        this.mblzPnum = req.getMblzPnum();
        this.recrCont = req.getRecrCont();
        this.recrPerd = req.getRecrPerd();
        this.linkId = req.getLinkId();
    }

}
