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

import com.its.op.dto.its.facility.TbFcltSubjDto;
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;

/**
 * 시설물 BOM 품목 정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("시설물 BOM 품목 정보")
@Entity
@Table(name = "TB_FCLT_SUBJ")
public class TbFcltSubj implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("품목 관리번호")  // N NUMBER(10)
    @Id
    @Column(name = "SUBJ_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long subjNmbr;

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

    @ApiModelProperty("품목 ID")  // N NUMBER(5)
    @Column(name = "SUBJ_ID", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer subjId;

    @ApiModelProperty("품목명")  // Y VARCHAR2(100)
    @Column(name = "SUBJ_NM", length = 100)
    private String subjNm;

    @ApiModelProperty("품목 세부사양")  // Y VARCHAR2(100)
    @Column(name = "SUBJ_DETL", length = 100)
    private String subjDetl;

    @ApiModelProperty("내구년한(월)")  // Y NUMBER(5)
    @Column(name = "VALID_MN", columnDefinition = "NUMBER", length = 5)
    private Integer validMn;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbFcltSubjDto toDto() {
        return TbFcltSubjDto.builder()
                .subjNmbr(this.subjNmbr)
                .fcltType(this.fcltType)
                .subjId(this.subjId)
                .subjNm(this.subjNm)
                .subjDetl(this.subjDetl)
                .validMn(this.validMn)
                .delYn(this.delYn)
                .build();
    }

    public TbFcltSubj(Long subjNmbr) {
        this.subjNmbr = subjNmbr;
    }

    public void updateInfo(TbFcltSubjDto.TbFcltSubjUpdReq req) {
        this.fcltType = req.getFcltType();
        this.subjId = req.getSubjId();
        this.subjNm = req.getSubjNm();
        this.subjDetl = req.getSubjDetl();
        this.validMn = req.getValidMn();
        this.delYn = req.getDelYn();
    }

}
