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

import com.its.api.its.model.dto.facility.TbFcltFailHsDto;
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_FCLT_FAIL_HS")
public class TbFcltFailHs implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("발생 일시")  // Y VARCHAR(14)
    @Column(name = "OCRR_DT", length = 14)
    private String ocrrDt;

    @ApiModelProperty("접수자 명")  // Y VARCHAR(30)
    @Column(name = "RCPR_NM", length = 30)
    private String rcprNm;

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

    @ApiModelProperty("추가 일시")  // Y VARCHAR(14)
    @Column(name = "ADTN_DT", length = 14)
    private String adtnDt;

    @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;

    @ApiModelProperty("장애 유형")  // Y VARCHAR(7)
    @Column(name = "FAIL_TYPE", length = 7)
    private String failType;

    @ApiModelProperty("장애 내용")  // Y VARCHAR(600)
    @Column(name = "FAIL_CONT", length = 600)
    private String failCont;

    @ApiModelProperty("시설물 ID")  // Y VARCHAR(50)
    @Column(name = "FCLT_ID", length = 50)
    private String fcltId;

    public TbFcltFailHsDto toDto() {
        return TbFcltFailHsDto.builder()
                .failHsSeq(this.failHsSeq)
                .ocrrDt(this.ocrrDt)
                .rcprNm(this.rcprNm)
                .adtnNm(this.adtnNm)
                .adtnDt(this.adtnDt)
                .chngNm(this.chngNm)
                .chngDt(this.chngDt)
                .failType(this.failType)
                .failCont(this.failCont)
                .fcltId(this.fcltId)
                .build();
    }

    public TbFcltFailHs(String failHsSeq) {
        this.failHsSeq = failHsSeq;
    }

    public void updateInfo(TbFcltFailHsDto.TbFcltFailHsUpdReq req) {
        this.ocrrDt = req.getOcrrDt();
        this.rcprNm = req.getRcprNm();
        this.adtnNm = req.getAdtnNm();
        this.adtnDt = req.getAdtnDt();
        this.chngNm = req.getChngNm();
        this.chngDt = req.getChngDt();
        this.failType = req.getFailType();
        this.failCont = req.getFailCont();
        this.fcltId = req.getFcltId();
    }

}
