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

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

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

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

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

    @ApiModelProperty("부품 ID")  // N NUMBER(5)
    @Column(name = "PART_ID", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer partId;

    @ApiModelProperty("부품명")  // Y VARCHAR2(100)
    @Column(name = "PART_NM", length = 100)
    private String partNm;

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

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

    @ApiModelProperty("재고 수량")  // Y NUMBER(5)
    @Column(name = "VALID_CNT", columnDefinition = "NUMBER", length = 5)
    private Integer validCnt;

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

    public TbFcltSubjPartDto toDto() {
        return TbFcltSubjPartDto.builder()
                .partNmbr(this.partNmbr)
                .subjNmbr(this.subjNmbr)
                .partId(this.partId)
                .partNm(this.partNm)
                .partDetl(this.partDetl)
                .validMn(this.validMn)
                .validCnt(this.validCnt)
                .delYn(this.delYn)
                .build();
    }

    public TbFcltSubjPart(Long partNmbr) {
        this.partNmbr = partNmbr;
    }

    public void updateInfo(TbFcltSubjPartDto.TbFcltSubjPartUpdReq req) {
        this.subjNmbr = req.getSubjNmbr();
        this.partId = req.getPartId();
        this.partNm = req.getPartNm();
        this.partDetl = req.getPartDetl();
        this.validMn = req.getValidMn();
        this.validCnt = req.getValidCnt();
        this.delYn = req.getDelYn();
    }

}
