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

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

/**
 * FMS 시설물 부품 입고 정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("FMS 시설물 부품 입고 정보")
@Entity
@Table(name = "TB_FCLT_SUBJ_PART_IN")
@IdClass(TbFcltSubjPartInKey.class)
public class TbFcltSubjPartIn 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 VARCHAR2(8)
    @Id
    @Column(name = "IN_DT", nullable = false, length = 8)
    private String inDt;

    @ApiModelProperty("단위(EA, ...)")  // Y VARCHAR2(10)
    @Column(name = "IN_UNIT", length = 10)
    private String inUnit;

    @ApiModelProperty("단위 수량당 단가")  // N NUMBER(5)
    @Column(name = "PER_AMT", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer perAmt;

    @ApiModelProperty("입고 갯수")  // N NUMBER(5)
    @Column(name = "IN_CNT", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer inCnt;

    @ApiModelProperty("매입 업체 ID")  // Y VARCHAR2(30)
    @Column(name = "CMPY_ID", length = 30)
    private String cmpyId;

    @ApiModelProperty("입고 담당자 사원 ID")  // Y VARCHAR2(10)
    @Column(name = "USER_ID", length = 10)
    private String userId;

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

    public TbFcltSubjPartInDto toDto() {
        return TbFcltSubjPartInDto.builder()
                .partNmbr(this.partNmbr)
                .inDt(this.inDt)
                .inUnit(this.inUnit)
                .perAmt(this.perAmt)
                .inCnt(this.inCnt)
                .cmpyId(this.cmpyId)
                .userId(this.userId)
                .validCnt(this.validCnt)
                .build();
    }

    public TbFcltSubjPartIn(Long partNmbr, String inDt) {
        this.partNmbr = partNmbr;
        this.inDt = inDt;
    }

    public void updateInfo(TbFcltSubjPartInDto.TbFcltSubjPartInUpdReq req) {
        this.inUnit = req.getInUnit();
        this.perAmt = req.getPerAmt();
        this.inCnt = req.getInCnt();
        this.cmpyId = req.getCmpyId();
        this.userId = req.getUserId();
        this.validCnt = req.getValidCnt();
    }

}
