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

import com.its.api.its.model.dto.facility.TbFcltFailRparHsDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 * 시설물 장애 조치 내역 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("시설물 장애 조치 내역")
@Entity
@Table(name = "TB_FCLT_FAIL_RPAR_HS")
@IdClass(TbFcltFailRparHsKey.class)
public class TbFcltFailRparHs implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("생성 일시")  // N VARCHAR(14)
    @Id
    @Column(name = "CRTN_DT", nullable = false, length = 14)
    private String crtnDt;

    @ApiModelProperty("장애 이력 일련번호")  // N VARCHAR(10)
    @Id
    @Column(name = "FAIL_HS_SEQ", nullable = false, length = 10)
    private String failHsSeq;

    @ApiModelProperty("작업자 명")  // Y VARCHAR(30)
    @Column(name = "WRKR_NM", length = 30)
    private String wrkrNm;

    @ApiModelProperty("작업 내용")  // Y VARCHAR(600)
    @Column(name = "WORK_CONT", length = 600)
    private String workCont;

    @ApiModelProperty("작업 시작 일시")  // Y VARCHAR(14)
    @Column(name = "WORK_STRT_DT", length = 14)
    private String workStrtDt;

    @ApiModelProperty("작업 종료 일시")  // Y VARCHAR(14)
    @Column(name = "WORK_END_DT", length = 14)
    private String workEndDt;

    @ApiModelProperty("작업 완료 여부")  // Y CHAR(1)
    @Column(name = "WORK_FINS_YN", columnDefinition = "CHAR", length = 1)
    private String workFinsYn;

    @ApiModelProperty("추가자 명")  // Y VARCHAR(30)
    @Column(name = "ADTN_NM", length = 30)
    private String adtnNm;

    @ApiModelProperty("변경자 명")  // Y VARCHAR(30)
    @Column(name = "CHNG_NM", length = 30)
    private String chngNm;

    @ApiModelProperty("변경 일시")  // Y VARCHAR(14)
    @Column(name = "CHNG_DT", length = 14)
    private String chngDt;

    public TbFcltFailRparHsDto toDto() {
        return TbFcltFailRparHsDto.builder()
                .crtnDt(this.crtnDt)
                .failHsSeq(this.failHsSeq)
                .wrkrNm(this.wrkrNm)
                .workCont(this.workCont)
                .workStrtDt(this.workStrtDt)
                .workEndDt(this.workEndDt)
                .workFinsYn(this.workFinsYn)
                .adtnNm(this.adtnNm)
                .chngNm(this.chngNm)
                .chngDt(this.chngDt)
                .build();
    }

    public TbFcltFailRparHs(String crtnDt, String failHsSeq) {
        this.crtnDt = crtnDt;
        this.failHsSeq = failHsSeq;
    }

    public void updateInfo(TbFcltFailRparHsDto.TbFcltFailRparHsUpdReq req) {
        this.wrkrNm = req.getWrkrNm();
        this.workCont = req.getWorkCont();
        this.workStrtDt = req.getWorkStrtDt();
        this.workEndDt = req.getWorkEndDt();
        this.workFinsYn = req.getWorkFinsYn();
        this.adtnNm = req.getAdtnNm();
        this.chngNm = req.getChngNm();
        this.chngDt = req.getChngDt();
    }

}
