package com.its.api.its.model.dto.vds;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.vds.TbVdsCtlr;
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;

/**
 * VDS 제어기 DTO Class
 */
@Data
@Builder
@ApiModel("TbVdsCtlrDto(VDS 제어기)")
public class TbVdsCtlrDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("제어기 관리 번호")  // N VARCHAR(20)
    @JsonProperty("ctlr_mngm_nmbr")
    private String ctlrMngmNmbr;

    @ApiModelProperty("VDS 제어기 ID")  // Y VARCHAR(30)
    @JsonProperty("vds_ctlr_id")
    private String vdsCtlrId;

    @ApiModelProperty("제어기 유형 코드")  // Y VARCHAR(7)
    @JsonProperty("ctlr_type_cd")
    private String ctlrTypeCd;

    @ApiModelProperty("유효 여부")  // Y CHAR(1)
    @JsonProperty("vald_yn")
    private String valdYn;

    @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("위치")  // Y VARCHAR(100)
    @JsonProperty("lctn")
    private String lctn;

    @ApiModelProperty("단말기 아이피")  // Y VARCHAR(20)
    @JsonProperty("trmn_ip")
    private String trmnIp;

    @ApiModelProperty("단말기 포트")  // Y VARCHAR(5)
    @JsonProperty("trmn_port")
    private String trmnPort;

    @ApiModelProperty("제어기 수집 주기")  // Y NUMBER(3)
    @JsonProperty("ctlr_clct_cycl")
    private Integer ctlrClctCycl;

    @ApiModelProperty("제어기 상태 주기")  // Y NUMBER(3)
    @JsonProperty("ctlr_stts_cycl")
    private Integer ctlrSttsCycl;

    @ApiModelProperty("루프 보드 개수")  // Y NUMBER(3)
    @JsonProperty("loop_bord_num")
    private Integer loopBordNum;

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

    // Code Description Field
    @ApiModelProperty("제어기 유형 코드 설명")
    @JsonProperty("ctlr_type_desc")    // CTLR_TYPE_CD
    private String ctlrTypeDesc;

    @ApiModelProperty("유효 여부 설명")
    @JsonProperty("vald_desc")    // VALD_YN
    private String valdDesc;

    @ApiModel("TbVdsCtlrUpdReq(VDS 제어기 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbVdsCtlrUpdReq {

        @ApiModelProperty("제어기 관리 번호, Nullable = N, VARCHAR(20)")  // N VARCHAR(20)
        @JsonProperty("ctlr_mngm_nmbr")
        @Size(min=1, max=20)
        private String ctlrMngmNmbr;

        @ApiModelProperty("VDS 제어기 ID, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("vds_ctlr_id")
        @Size(min=1, max=30)
        private String vdsCtlrId;

        @ApiModelProperty("제어기 유형 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("ctlr_type_cd")
        @Size(min=1, max=7)
        private String ctlrTypeCd;

        @ApiModelProperty("유효 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("vald_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String valdYn;

        @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("위치, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("lctn")
        @Size(min=1, max=100)
        private String lctn;

        @ApiModelProperty("단말기 아이피, Nullable = Y, VARCHAR(20)")  // Y VARCHAR(20)
        @JsonProperty("trmn_ip")
        @Size(min=1, max=20)
        private String trmnIp;

        @ApiModelProperty("단말기 포트, Nullable = Y, VARCHAR(5)")  // Y VARCHAR(5)
        @JsonProperty("trmn_port")
        @Size(min=1, max=5)
        private String trmnPort;

        @ApiModelProperty("제어기 수집 주기, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("ctlr_clct_cycl")
        @PositiveOrZero
        private Integer ctlrClctCycl;

        @ApiModelProperty("제어기 상태 주기, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("ctlr_stts_cycl")
        @PositiveOrZero
        private Integer ctlrSttsCycl;

        @ApiModelProperty("루프 보드 개수, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("loop_bord_num")
        @PositiveOrZero
        private Integer loopBordNum;

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

        @Builder
        public TbVdsCtlrUpdReq(String ctlr_mngm_nmbr, String vds_ctlr_id, String ctlr_type_cd, String vald_yn, Double x_crdn, Double y_crdn, String lctn, String trmn_ip, String trmn_port, Integer ctlr_clct_cycl, Integer ctlr_stts_cycl, Integer loop_bord_num, String del_yn) {
            this.ctlrMngmNmbr = ctlr_mngm_nmbr;
            this.vdsCtlrId = vds_ctlr_id;
            this.ctlrTypeCd = ctlr_type_cd;
            this.valdYn = vald_yn;
            this.xCrdn = x_crdn;
            this.yCrdn = y_crdn;
            this.lctn = lctn;
            this.trmnIp = trmn_ip;
            this.trmnPort = trmn_port;
            this.ctlrClctCycl = ctlr_clct_cycl;
            this.ctlrSttsCycl = ctlr_stts_cycl;
            this.loopBordNum = loop_bord_num;
            this.delYn = del_yn;
        }

        public TbVdsCtlr toEntity() {
            return TbVdsCtlr.builder()
                    .ctlrMngmNmbr(this.ctlrMngmNmbr)
                    .vdsCtlrId(this.vdsCtlrId)
                    .ctlrTypeCd(this.ctlrTypeCd)
                    .valdYn(this.valdYn)
                    .xCrdn(this.xCrdn)
                    .yCrdn(this.yCrdn)
                    .lctn(this.lctn)
                    .trmnIp(this.trmnIp)
                    .trmnPort(this.trmnPort)
                    .ctlrClctCycl(this.ctlrClctCycl)
                    .ctlrSttsCycl(this.ctlrSttsCycl)
                    .loopBordNum(this.loopBordNum)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
