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

import com.its.op.dto.its.facility.TbFcltFailTypeDto;
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.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_TYPE")
public class TbFcltFailType implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("장애유형 명")  // N VARCHAR2(30)
    @Column(name = "FAIL_CD_NM", nullable = false, length = 30)
    private String failCdNm;

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

    public TbFcltFailTypeDto toDto() {
        return TbFcltFailTypeDto.builder()
                .failCd(this.failCd)
                .failCdNm(this.failCdNm)
                .useYn(this.useYn)
                .build();
    }

    public TbFcltFailType(String failCd) {
        this.failCd = failCd;
    }

    public void updateInfo(TbFcltFailTypeDto.TbFcltFailTypeUpdReq req) {
        this.failCdNm = req.getFailCdNm();
        this.useYn = req.getUseYn();
    }

}
