package com.its.op.dto.its.rse;

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

/**
 * RSE 마스터 정보 DTO Class
 */
@Data
@Builder
@ApiModel("TbRseCtlrDto(RSE 마스터 정보)")
public class TbRseCtlrDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 제어기 번호")  // N NUMBER(10)
    @JsonProperty("rse_ctlr_nmbr")
    private Long rseCtlrNmbr;

    @ApiModelProperty("RSE 제어기 ID")  // Y VARCHAR2(30)
    @JsonProperty("rse_ctlr_id")
    private String rseCtlrId;

    @ApiModelProperty("RSE 명칭")  // Y VARCHAR2(40)
    @JsonProperty("rse_nm")
    private String rseNm;

    @ApiModelProperty("RSE 제어기 아이피")  // Y VARCHAR2(20)
    @JsonProperty("rse_ctlr_ip")
    private String rseCtlrIp;

    @ApiModelProperty("RSE 제어기 포트")  // Y NUMBER(5)
    @JsonProperty("rse_ctlr_port")
    private Integer rseCtlrPort;

    @ApiModelProperty("RSE 제어기 지역번호")  // Y NUMBER(5)
    @JsonProperty("rse_ctlr_local_no")
    private Integer rseCtlrLocalNo;

    @ApiModelProperty("RSE 유형 코드('RSET')")  // Y VARCHAR2(7)
    @JsonProperty("rse_type_cd")
    private String rseTypeCd;

    @ApiModelProperty("설치 위치 명")  // Y VARCHAR2(40)
    @JsonProperty("istl_lctn_nm")
    private String istlLctnNm;

    @ApiModelProperty("설치 위치 주소")  // Y VARCHAR2(200)
    @JsonProperty("istl_lctn_addr")
    private String istlLctnAddr;

    @ApiModelProperty("X 좌표")  // Y NUMBER(11,8)
    @JsonProperty("x_crdn")
    private Double xCrdn;

    @ApiModelProperty("Y 좌표")  // Y NUMBER(10,8)
    @JsonProperty("y_crdn")
    private Double yCrdn;

    @ApiModelProperty("MCU ID")  // Y VARCHAR2(30)
    @JsonProperty("rse_mcu_id")
    private String rseMcuId;

    @ApiModelProperty("로그 접속 아이디")  // Y VARCHAR2(64)
    @JsonProperty("log_cnnc_id")
    private String logCnncId;

    @ApiModelProperty("로그 접속 비밀번호")  // Y VARCHAR2(64)
    @JsonProperty("log_cnnc_pw")
    private String logCnncPw;

    @ApiModelProperty("제조 업체 코드")  // Y NUMBER(5)
    @JsonProperty("mnfc_cmpy_cd")
    private Integer mnfcCmpyCd;

    @ApiModelProperty("수집 이상 기준")  // Y NUMBER(7)
    @JsonProperty("clct_abnr_basi")
    private Integer clctAbnrBasi;

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

    // Code Description Field
    @ApiModelProperty("RSE 유형 코드('RSET') 설명")
    @JsonProperty("rse_type_desc")    // RSE_TYPE_CD
    private String rseTypeDesc;

    @ApiModelProperty("제조 업체 코드 설명")
    @JsonProperty("mnfc_cmpy_desc")    // MNFC_CMPY_CD
    private String mnfcCmpyDesc;

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

    @ApiModel("TbRseCtlrUpdReq(RSE 마스터 정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbRseCtlrUpdReq {

        @ApiModelProperty("RSE 제어기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("rse_ctlr_nmbr")
        @PositiveOrZero
        private Long rseCtlrNmbr;

        @ApiModelProperty("RSE 제어기 ID, Nullable = Y, VARCHAR2(30)")  // Y VARCHAR2(30)
        @JsonProperty("rse_ctlr_id")
        @Size(min=1, max=30)
        private String rseCtlrId;

        @ApiModelProperty("RSE 명칭, Nullable = Y, VARCHAR2(40)")  // Y VARCHAR2(40)
        @JsonProperty("rse_nm")
        @Size(min=1, max=40)
        private String rseNm;

        @ApiModelProperty("RSE 제어기 아이피, Nullable = Y, VARCHAR2(20)")  // Y VARCHAR2(20)
        @JsonProperty("rse_ctlr_ip")
        @Size(min=1, max=20)
        private String rseCtlrIp;

        @ApiModelProperty("RSE 제어기 포트, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("rse_ctlr_port")
        @PositiveOrZero
        private Integer rseCtlrPort;

        @ApiModelProperty("RSE 제어기 지역번호, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("rse_ctlr_local_no")
        @PositiveOrZero
        private Integer rseCtlrLocalNo;

        @ApiModelProperty("RSE 유형 코드('RSET'), Nullable = Y, VARCHAR2(7)")  // Y VARCHAR2(7)
        @JsonProperty("rse_type_cd")
        @Size(min=1, max=7)
        private String rseTypeCd;

        @ApiModelProperty("설치 위치 명, Nullable = Y, VARCHAR2(40)")  // Y VARCHAR2(40)
        @JsonProperty("istl_lctn_nm")
        @Size(min=1, max=40)
        private String istlLctnNm;

        @ApiModelProperty("설치 위치 주소, Nullable = Y, VARCHAR2(200)")  // Y VARCHAR2(200)
        @JsonProperty("istl_lctn_addr")
        @Size(min=1, max=200)
        private String istlLctnAddr;

        @ApiModelProperty("X 좌표, , NUMBER(11,8)")  // Y NUMBER(11,8)
        @JsonProperty("x_crdn")
        private Double xCrdn;

        @ApiModelProperty("Y 좌표, , NUMBER(10,8)")  // Y NUMBER(10,8)
        @JsonProperty("y_crdn")
        private Double yCrdn;

        @ApiModelProperty("MCU ID, Nullable = Y, VARCHAR2(30)")  // Y VARCHAR2(30)
        @JsonProperty("rse_mcu_id")
        @Size(min=1, max=30)
        private String rseMcuId;

        @ApiModelProperty("로그 접속 아이디, Nullable = Y, VARCHAR2(64)")  // Y VARCHAR2(64)
        @JsonProperty("log_cnnc_id")
        @Size(min=1, max=64)
        private String logCnncId;

        @ApiModelProperty("로그 접속 비밀번호, Nullable = Y, VARCHAR2(64)")  // Y VARCHAR2(64)
        @JsonProperty("log_cnnc_pw")
        @Size(min=1, max=64)
        private String logCnncPw;

        @ApiModelProperty("제조 업체 코드, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("mnfc_cmpy_cd")
        @PositiveOrZero
        private Integer mnfcCmpyCd;

        @ApiModelProperty("수집 이상 기준, Nullable = Y, NUMBER(7)")  // Y NUMBER(7)
        @JsonProperty("clct_abnr_basi")
        @PositiveOrZero
        private Integer clctAbnrBasi;

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

        @Builder
        public TbRseCtlrUpdReq(Long rse_ctlr_nmbr, String rse_ctlr_id, String rse_nm, String rse_ctlr_ip, Integer rse_ctlr_port, Integer rse_ctlr_local_no, String rse_type_cd, String istl_lctn_nm, String istl_lctn_addr, Double x_crdn, Double y_crdn, String rse_mcu_id, String log_cnnc_id, String log_cnnc_pw, Integer mnfc_cmpy_cd, Integer clct_abnr_basi, String del_yn) {
            this.rseCtlrNmbr = rse_ctlr_nmbr;
            this.rseCtlrId = rse_ctlr_id;
            this.rseNm = rse_nm;
            this.rseCtlrIp = rse_ctlr_ip;
            this.rseCtlrPort = rse_ctlr_port;
            this.rseCtlrLocalNo = rse_ctlr_local_no;
            this.rseTypeCd = rse_type_cd;
            this.istlLctnNm = istl_lctn_nm;
            this.istlLctnAddr = istl_lctn_addr;
            this.xCrdn = x_crdn;
            this.yCrdn = y_crdn;
            this.rseMcuId = rse_mcu_id;
            this.logCnncId = log_cnnc_id;
            this.logCnncPw = log_cnnc_pw;
            this.mnfcCmpyCd = mnfc_cmpy_cd;
            this.clctAbnrBasi = clct_abnr_basi;
            this.delYn = del_yn;
        }

        public TbRseCtlr toEntity() {
            return TbRseCtlr.builder()
                    .rseCtlrNmbr(this.rseCtlrNmbr)
                    .rseCtlrId(this.rseCtlrId)
                    .rseNm(this.rseNm)
                    .rseCtlrIp(this.rseCtlrIp)
                    .rseCtlrPort(this.rseCtlrPort)
                    .rseCtlrLocalNo(this.rseCtlrLocalNo)
                    .rseTypeCd(this.rseTypeCd)
                    .istlLctnNm(this.istlLctnNm)
                    .istlLctnAddr(this.istlLctnAddr)
                    .xCrdn(this.xCrdn)
                    .yCrdn(this.yCrdn)
                    .rseMcuId(this.rseMcuId)
                    .logCnncId(this.logCnncId)
                    .logCnncPw(this.logCnncPw)
                    .mnfcCmpyCd(this.mnfcCmpyCd)
                    .clctAbnrBasi(this.clctAbnrBasi)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
