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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.facility.TbFcltSubj;
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;

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

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

    @ApiModelProperty("시설물 유형")  // Y VARCHAR2(7)
    @JsonProperty("fclt_type")
    private String fcltType;

    @ApiModelProperty("품목 ID")  // N NUMBER(5)
    @JsonProperty("subj_id")
    private Integer subjId;

    @ApiModelProperty("품목명")  // Y VARCHAR2(100)
    @JsonProperty("subj_nm")
    private String subjNm;

    @ApiModelProperty("품목 세부사양")  // Y VARCHAR2(100)
    @JsonProperty("subj_detl")
    private String subjDetl;

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

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

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

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

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

        @ApiModelProperty("시설물 유형, Nullable = Y, VARCHAR2(7)")  // Y VARCHAR2(7)
        @JsonProperty("fclt_type")
        @Size(min=1, max=7)
        private String fcltType;

        @ApiModelProperty("품목 ID, Nullable = N, NUMBER(5)")  // N NUMBER(5)
        @JsonProperty("subj_id")
        @PositiveOrZero
        private Integer subjId;

        @ApiModelProperty("품목명, Nullable = Y, VARCHAR2(100)")  // Y VARCHAR2(100)
        @JsonProperty("subj_nm")
        @Size(min=1, max=100)
        private String subjNm;

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

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

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

        @Builder
        public TbFcltSubjUpdReq(Long subj_nmbr, String fclt_type, Integer subj_id, String subj_nm, String subj_detl, Integer valid_mn, String del_yn) {
            this.subjNmbr = subj_nmbr;
            this.fcltType = fclt_type;
            this.subjId = subj_id;
            this.subjNm = subj_nm;
            this.subjDetl = subj_detl;
            this.validMn = valid_mn;
            this.delYn = del_yn;
        }

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

    }

}
