package com.its.op.dto.its.facility;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.facility.TbFcltSubjPart;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.Pattern;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * FMS 시설물 품목 별 부품 정보 DTO Class
 */
@Data
@Builder
@ApiModel("TbFcltSubjPartDto(FMS 시설물 품목 별 부품 정보)")
public class TbFcltSubjPartDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("부품 관리번호")  // N NUMBER(10)
    @JsonProperty("part_nmbr")
    private Long partNmbr;

    @ApiModelProperty("품목 관리번호")  // N NUMBER(10)
    @JsonProperty("subj_nmbr")
    private Long subjNmbr;

    @ApiModelProperty("부품 ID")  // N NUMBER(5)
    @JsonProperty("part_id")
    private Integer partId;

    @ApiModelProperty("부품명")  // Y VARCHAR2(100)
    @JsonProperty("part_nm")
    private String partNm;

    @ApiModelProperty("부품 세부사양")  // Y VARCHAR2(100)
    @JsonProperty("part_detl")
    private String partDetl;

    @ApiModelProperty("내구년한(월)")  // Y NUMBER(5)
    @JsonProperty("valid_mn")
    private Integer validMn;

    @ApiModelProperty("재고 수량")  // Y NUMBER(5)
    @JsonProperty("valid_cnt")
    private Integer validCnt;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @JsonProperty("del_yn")
    private String delYn;

    // Code Description Field
    @ApiModelProperty("삭제 여부 설명")
    @JsonProperty("del_desc")    // DEL_YN
    private String delDesc;

    @ApiModel("TbFcltSubjPartUpdReq(FMS 시설물 품목 별 부품 정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbFcltSubjPartUpdReq {

        @ApiModelProperty("부품 관리번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("part_nmbr")
        @PositiveOrZero
        private Long partNmbr;

        @ApiModelProperty("품목 관리번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("subj_nmbr")
        @PositiveOrZero
        private Long subjNmbr;

        @ApiModelProperty("부품 ID, Nullable = N, NUMBER(5)")  // N NUMBER(5)
        @JsonProperty("part_id")
        @PositiveOrZero
        private Integer partId;

        @ApiModelProperty("부품명, Nullable = Y, VARCHAR2(100)")  // Y VARCHAR2(100)
        @JsonProperty("part_nm")
        @Size(min=1, max=100)
        private String partNm;

        @ApiModelProperty("부품 세부사양, Nullable = Y, VARCHAR2(100)")  // Y VARCHAR2(100)
        @JsonProperty("part_detl")
        @Size(min=1, max=100)
        private String partDetl;

        @ApiModelProperty("내구년한(월), Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("valid_mn")
        @PositiveOrZero
        private Integer validMn;

        @ApiModelProperty("재고 수량, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("valid_cnt")
        @PositiveOrZero
        private Integer validCnt;

        @ApiModelProperty("삭제 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("del_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String delYn;

        @Builder
        public TbFcltSubjPartUpdReq(Long part_nmbr, Long subj_nmbr, Integer part_id, String part_nm, String part_detl, Integer valid_mn, Integer valid_cnt, String del_yn) {
            this.partNmbr = part_nmbr;
            this.subjNmbr = subj_nmbr;
            this.partId = part_id;
            this.partNm = part_nm;
            this.partDetl = part_detl;
            this.validMn = valid_mn;
            this.validCnt = valid_cnt;
            this.delYn = del_yn;
        }

        public TbFcltSubjPart toEntity() {
            return TbFcltSubjPart.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();
        }

    }

}
