package com.its.op.dto.its.database;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.dto.its.code.TbCmmnCdDto;
import com.its.op.entity.its.database.TbCnctIntn;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 * 연계 기관 DTO Class
 */
@Data
@Builder
@ApiModel("TbCnctIntnDto(연계 기관)")
public class TbCnctIntnDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("연계 기관 관리 번호")  // N NUMBER(10)
    @JsonProperty("cnct_intn_mngm_nmbr")
    private Long cnctIntnMngmNmbr;

    @ApiModelProperty("연계 기관 명")  // Y VARCHAR(50)
    @JsonProperty("cnct_intn_nm")
    private String cnctIntnNm;

    @ApiModelProperty("연계 기관 유형 코드")  // Y VARCHAR(7)
    @JsonProperty("cnct_intn_type_cd")
    private String cnctIntnTypeCd;

    @ApiModelProperty("연계 기관 전화번호")  // Y VARCHAR(128)
    @JsonProperty("cnct_intn_tel")
    private String cnctIntnTel;

    @ApiModelProperty("연계 기관 주소")  // Y VARCHAR(200)
    @JsonProperty("cnct_intn_addr")
    private String cnctIntnAddr;

    @ApiModelProperty("비고")  // Y VARCHAR(600)
    @JsonProperty("rmrk")
    private String rmrk;

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

    // Code Description Field
    @ApiModelProperty("연계 기관 유형 코드 설명")
    @JsonProperty("cnct_intn_type_desc")    // CNCT_INTN_TYPE_CD
    private String cnctIntnTypeDesc;

    @ApiModel("TbCnctIntnUpdReq(연계 기관 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbCnctIntnUpdReq {

        @ApiModelProperty("연계 기관 관리 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("cnct_intn_mngm_nmbr")
        @Positive
        private Long cnctIntnMngmNmbr;

        @ApiModelProperty("연계 기관 명, Nullable = Y, VARCHAR(50)")  // Y VARCHAR(50)
        @JsonProperty("cnct_intn_nm")
        @Size(min=1, max=50)
        private String cnctIntnNm;

        @ApiModelProperty("연계 기관 유형 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("cnct_intn_type_cd")
        @Size(min=1, max=7)
        private String cnctIntnTypeCd;

        @ApiModelProperty("연계 기관 전화번호, Nullable = Y, VARCHAR(128)")  // Y VARCHAR(128)
        @JsonProperty("cnct_intn_tel")
        @Size(min=1, max=128)
        private String cnctIntnTel;

        @ApiModelProperty("연계 기관 주소, Nullable = Y, VARCHAR(200)")  // Y VARCHAR(200)
        @JsonProperty("cnct_intn_addr")
        @Size(min=1, max=200)
        private String cnctIntnAddr;

        @ApiModelProperty("비고, Nullable = Y, VARCHAR(600)")  // Y VARCHAR(600)
        @JsonProperty("rmrk")
        //@Size(min=1, max=600)
        @Size(max=600)
        private String rmrk;

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

        @Builder
        public TbCnctIntnUpdReq(Long cnct_intn_mngm_nmbr, String cnct_intn_nm, String cnct_intn_type_cd, String cnct_intn_tel, String cnct_intn_addr, String rmrk, String frst_regr_nmbr, String frst_rgst_dt, String last_crpr_nmbr, String last_crct_dt, String del_yn) {
            this.cnctIntnMngmNmbr = cnct_intn_mngm_nmbr;
            this.cnctIntnNm = cnct_intn_nm;
            this.cnctIntnTypeCd = cnct_intn_type_cd;
            this.cnctIntnTel = cnct_intn_tel;
            this.cnctIntnAddr = cnct_intn_addr;
            this.rmrk = rmrk;
            this.delYn = del_yn;
        }

        public TbCnctIntn toEntity() {
            return TbCnctIntn.builder()
                    .cnctIntnMngmNmbr(this.cnctIntnMngmNmbr)
                    .cnctIntnNm(this.cnctIntnNm)
                    .cnctIntnTypeCd(this.cnctIntnTypeCd)
                    .cnctIntnTel(this.cnctIntnTel)
                    .cnctIntnAddr(this.cnctIntnAddr)
                    .rmrk(this.rmrk)
                    .delYn(this.delYn)
                    .build();
        }

    }

    @Getter
    public static class TbCnctType {

        @ApiModelProperty("연계 기관 유형 코드")  // Y VARCHAR(7)
        @JsonProperty("cnct_intn_type_cd")
        private String cnctIntnTypeCd;

        @ApiModelProperty("연계 기관 유형 명")
        @JsonProperty("cnct_intn_type_nm")
        private String cnctIntnTypeNm;

        @ApiModelProperty("연계 기관 유형 설명")
        @JsonProperty("cnct_intn_type_desc")
        private String cnctIntnTypeDesc;

        public TbCnctType(TbCmmnCdDto entity) {
            this.cnctIntnTypeCd   = entity.getCmmnCd();
            this.cnctIntnTypeNm   = entity.getCmmnCdKorNm();
            this.cnctIntnTypeDesc = "[" + this.cnctIntnTypeCd + "]" + this.cnctIntnTypeNm;
        }
    }

}
