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

import com.its.op.dto.its.facility.TbFcltSubjPartOutDto;
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_OUT")
@IdClass(TbFcltSubjPartOutKey.class)
public class TbFcltSubjPartOut 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("출고 대상 시설물 ID")  // N VARCHAR2(30)
    @Id
    @Column(name = "FCLT_ID", nullable = false, length = 30)
    private String fcltId;

    @ApiModelProperty("출고 일자")  // N VARCHAR2(8)
    @Id
    @Column(name = "OUT_DT", nullable = false, length = 8)
    private String outDt;

    @ApiModelProperty("출고 갯수")  // N NUMBER(5)
    @Column(name = "OUT_CNT", nullable = false, columnDefinition = "NUMBER", length = 5)
    private Integer outCnt;

    @ApiModelProperty("출고 내용")  // Y VARCHAR2(200)
    @Column(name = "OUT_DESC", length = 200)
    private String outDesc;

    @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 TbFcltSubjPartOutDto toDto() {
        return TbFcltSubjPartOutDto.builder()
                .partNmbr(this.partNmbr)
                .fcltId(this.fcltId)
                .outDt(this.outDt)
                .outCnt(this.outCnt)
                .outDesc(this.outDesc)
                .userId(this.userId)
                .validCnt(this.validCnt)
                .build();
    }

    public TbFcltSubjPartOut(Long partNmbr, String fcltId, String outDt) {
        this.partNmbr = partNmbr;
        this.fcltId = fcltId;
        this.outDt = outDt;
    }

    public void updateInfo(TbFcltSubjPartOutDto.TbFcltSubjPartOutUpdReq req) {
        this.outCnt = req.getOutCnt();
        this.outDesc = req.getOutDesc();
        this.userId = req.getUserId();
        this.validCnt = req.getValidCnt();
    }

}
