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

import com.its.op.dto.its.facility.TbFcltFailStupDto;
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_STUP")
@IdClass(TbFcltFailStupKey.class)
public class TbFcltFailStup implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("시설물 유형")  // N VARCHAR2(7)
    @Id
    @Column(name = "FCLT_TYPE", nullable = false, length = 7)
    private String fcltType;

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

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

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

    public TbFcltFailStupDto toDto() {
        return TbFcltFailStupDto.builder()
                .fcltType(this.fcltType)
                .failOcrrCd(this.failOcrrCd)
                .failCd(this.failCd)
                .useYn(this.useYn)
                .build();
    }

    public TbFcltFailStup(String fcltType, String failOcrrCd, String failCd) {
        this.fcltType = fcltType;
        this.failOcrrCd = failOcrrCd;
        this.failCd = failCd;
    }

    public void updateInfo(TbFcltFailStupDto.TbFcltFailStupUpdReq req) {
        this.useYn = req.getUseYn();
    }

}
