package com.its.op.entity.its.facility;

import com.its.op.dto.its.facility.TbFcltFailActDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 시설물 장애 발생 조치 정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("시설물 장애 발생 조치 정보")
@Entity
@Table(name = "TB_FCLT_FAIL_ACT")
@IdClass(TbFcltFailActKey.class)
public class TbFcltFailAct implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("장애관리번호(YYYYMMNNNN)")  // N VARCHAR2(10)
    @Id
    @Column(name = "FAIL_NO", nullable = false, length = 10)
    private String failNo;

    @ApiModelProperty("조치차수")  // N NUMBER(3)
    @Id
    @Column(name = "ACT_SEQ", nullable = false, columnDefinition = "NUMBER", length = 3)
    private Integer actSeq;

    @ApiModelProperty("등록일시")  // N VARCHAR2(14)
    @Column(name = "REG_DT", nullable = false, length = 14)
    private String regDt;

    @ApiModelProperty("장애조치자명")  // Y VARCHAR2(30)
    @Column(name = "ACT_MAN", length = 30)
    private String actMan;

    @ApiModelProperty("진행상태")  // Y VARCHAR2(7)
    @Column(name = "STEP_CD", length = 7)
    private String stepCd;

    @ApiModelProperty("장애 발생 구분코드")  // Y VARCHAR2(7)
    @Column(name = "FAIL_OCRR_CD", length = 7)
    private String failOcrrCd;

    @ApiModelProperty("장애유형")  // Y VARCHAR2(7)
    @Column(name = "FAIL_CD", length = 7)
    private String failCd;

    @ApiModelProperty("장애조치방법")  // Y VARCHAR2(7)
    @Column(name = "FAIL_ACT_CD", length = 7)
    private String failActCd;

    @ApiModelProperty("장애 부품 관리번호")  // Y NUMBER(10)
    @Column(name = "PART_NMBR", columnDefinition = "NUMBER", length = 10)
    private Long partNmbr;

    @ApiModelProperty("장애조치일시")  // Y VARCHAR2(14)
    @Column(name = "ACT_DT", length = 14)
    private String actDt;

    @ApiModelProperty("서비스영향")  // Y CHAR(1)
    @Column(name = "SVC_YN", columnDefinition = "CHAR", length = 1)
    private String svcYn;

    @ApiModelProperty("서비스개시일시")  // Y VARCHAR2(14)
    @Column(name = "SVC_STR_DT", length = 14)
    private String svcStrDt;

    @ApiModelProperty("장애원인")  // Y VARCHAR2(256)
    @Column(name = "FAIL_CAUSE", length = 256)
    private String failCause;

    @ApiModelProperty("조치내용")  // Y VARCHAR2(256)
    @Column(name = "ACT_DESC", length = 256)
    private String actDesc;

    @ApiModelProperty("기타비고")  // Y VARCHAR2(256)
    @Column(name = "ETC_RMK", length = 256)
    private String etcRmk;

    @ApiModelProperty("사용여부")  // Y CHAR(1)
    @Column(name = "USE_YN", columnDefinition = "CHAR", length = 1)
    private String useYn;

    public TbFcltFailActDto toDto() {
        TbFcltFailActDto dto = TbFcltFailActDto.builder()
                .failNo(this.failNo)
                .actSeq(this.actSeq)
                .regDt(this.regDt)
                .actMan(this.actMan)
                .stepCd(this.stepCd)
                .failOcrrCd(this.failOcrrCd)
                .failCd(this.failCd)
                .failActCd(this.failActCd)
                .partNmbr(this.partNmbr)
                .actDt(this.actDt)
                .svcYn(this.svcYn)
                .svcStrDt(this.svcStrDt)
                .failCause(this.failCause)
                .actDesc(this.actDesc)
                .etcRmk(this.etcRmk)
                .useYn(this.useYn)
                .build();

        // TODO
        // 코드 설명 추가
        return dto;
    }

    public TbFcltFailAct(String failNo, Integer actSeq) {
        this.failNo = failNo;
        this.actSeq = actSeq;
    }

    public void updateInfo(TbFcltFailActDto.TbFcltFailActUpdReq req) {
        this.regDt = req.getRegDt();
        this.actMan = req.getActMan();
        this.stepCd = req.getStepCd();
        this.failOcrrCd = req.getFailOcrrCd();
        this.failCd = req.getFailCd();
        this.failActCd = req.getFailActCd();
        this.partNmbr = req.getPartNmbr();
        this.actDt = req.getActDt();
        this.svcYn = req.getSvcYn();
        this.svcStrDt = req.getSvcStrDt();
        this.failCause = req.getFailCause();
        this.actDesc = req.getActDesc();
        this.etcRmk = req.getEtcRmk();
        this.useYn = req.getUseYn();
    }

}
