package com.its.op.dto.its.vds;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.vds.TbVdsCtlr;
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.PositiveOrZero;
import javax.validation.constraints.Size;
import java.io.Serializable;

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

    @ApiModelProperty("VDS 제어기 관리 번호")  // N NUMBER(10)
    @JsonProperty("vds_ctlr_nmbr")
    private Long vdsCtlrNmbr;

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

    @ApiModelProperty("VDS 명칭")  // Y VARCHAR2(40)
    @JsonProperty("vds_nm")
    private String vdsNm;

    @ApiModelProperty("VDS 제어기 아이피")  // Y VARCHAR2(20)
    @JsonProperty("vds_ctlr_ip")
    private String vdsCtlrIp;

    @ApiModelProperty("VDS 제어기 포트")  // Y NUMBER(5)
    @JsonProperty("vds_ctlr_port")
    private Integer vdsCtlrPort;

    @ApiModelProperty("VDS 제어기 지역번호")  // Y NUMBER(5)
    @JsonProperty("vds_ctlr_local_no")
    private Integer vdsCtlrLocalNo;

    @ApiModelProperty("VDS 유형 코드('VDST')")  // Y VARCHAR2(7)
    @JsonProperty("vds_type_cd")
    private String vdsTypeCd;

    @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("그룹번호")  // Y NUMBER(5)
    @JsonProperty("group_no")
    private Integer groupNo;

    @ApiModelProperty("FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)")  // Y NUMBER(3)
    @JsonProperty("fan_mode")
    private Integer fanMode;

    @ApiModelProperty("팬 동작 온도")  // Y NUMBER(3)
    @JsonProperty("fan_run_tmpr")
    private Integer fanRunTmpr;

    @ApiModelProperty("히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)")  // Y NUMBER(3)
    @JsonProperty("hetr_mode")
    private Integer hetrMode;

    @ApiModelProperty("히터 동작 온도")  // Y NUMBER(3)
    @JsonProperty("hetr_run_tmpr")
    private Integer hetrRunTmpr;

    @ApiModelProperty("검지 전체 차로수")  // Y NUMBER(2)
    @JsonProperty("detect_lanes")
    private Integer detectLanes;

    @ApiModelProperty("교통정보수집주기")  // Y NUMBER(3)
    @JsonProperty("traf_clct_cycl")
    private Integer trafClctCycl;

    @ApiModelProperty("상태정보수집주기")  // Y NUMBER(3)
    @JsonProperty("stts_clct_cycl")
    private Integer sttsClctCycl;

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

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

    // Code Description Field
    @ApiModelProperty("VDS 유형 코드('VDST') 설명")
    @JsonProperty("vds_type_desc")    // VDS_TYPE_CD
    private String vdsTypeDesc;

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

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

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

        @ApiModelProperty("VDS 제어기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("vds_ctlr_nmbr")
        @Positive
        private Long vdsCtlrNmbr;

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

        @ApiModelProperty("VDS 명칭, Nullable = Y, VARCHAR2(40)")  // Y VARCHAR2(40)
        @JsonProperty("vds_nm")
        @Size(min=1, max=40)
        private String vdsNm;

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

        @ApiModelProperty("VDS 제어기 포트, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("vds_ctlr_port")
        @PositiveOrZero
        private Integer vdsCtlrPort;

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

        @ApiModelProperty("VDS 유형 코드('VDST'), Nullable = Y, VARCHAR2(7)")  // Y VARCHAR2(7)
        @JsonProperty("vds_type_cd")
        @Size(min=1, max=7)
        private String vdsTypeCd;

        @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(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("그룹번호, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("group_no")
        @PositiveOrZero
        private Integer groupNo;

        @ApiModelProperty("FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음), Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("fan_mode")
        @PositiveOrZero
        private Integer fanMode;

        @ApiModelProperty("팬 동작 온도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("fan_run_tmpr")
        @PositiveOrZero
        private Integer fanRunTmpr;

        @ApiModelProperty("히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음), Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("hetr_mode")
        @PositiveOrZero
        private Integer hetrMode;

        @ApiModelProperty("히터 동작 온도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("hetr_run_tmpr")
        @PositiveOrZero
        private Integer hetrRunTmpr;

        @ApiModelProperty("검지 전체 차로수, Nullable = Y, NUMBER(2)")  // Y NUMBER(2)
        @JsonProperty("detect_lanes")
        @PositiveOrZero
        private Integer detectLanes;

        @ApiModelProperty("교통정보수집주기, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("traf_clct_cycl")
        @Positive
        private Integer trafClctCycl;

        @ApiModelProperty("상태정보수집주기, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("stts_clct_cycl")
        @Positive
        private Integer sttsClctCycl;

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

        @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(Long vds_ctlr_nmbr, String vds_ctlr_id, String vds_nm, String vds_ctlr_ip, Integer vds_ctlr_port, Integer vds_ctlr_local_no, String vds_type_cd, String istl_lctn_nm, String istl_lctn_addr, Double x_crdn, Double y_crdn, Integer group_no, Integer fan_mode, Integer fan_run_tmpr, Integer hetr_mode, Integer hetr_run_tmpr, Integer detect_lanes, Integer traf_clct_cycl, Integer stts_clct_cycl, String vald_yn, String del_yn) {
            this.vdsCtlrNmbr = vds_ctlr_nmbr;
            this.vdsCtlrId = vds_ctlr_id;
            this.vdsNm = vds_nm;
            this.vdsCtlrIp = vds_ctlr_ip;
            this.vdsCtlrPort = vds_ctlr_port;
            this.vdsCtlrLocalNo = vds_ctlr_local_no;
            this.vdsTypeCd = vds_type_cd;
            this.istlLctnNm = istl_lctn_nm;
            this.istlLctnAddr = istl_lctn_addr;
            this.xCrdn = x_crdn;
            this.yCrdn = y_crdn;
            this.groupNo = group_no;
            this.fanMode = fan_mode;
            this.fanRunTmpr = fan_run_tmpr;
            this.hetrMode = hetr_mode;
            this.hetrRunTmpr = hetr_run_tmpr;
            this.detectLanes = detect_lanes;
            this.trafClctCycl = traf_clct_cycl;
            this.sttsClctCycl = stts_clct_cycl;
            this.valdYn = vald_yn;
            this.delYn = del_yn;
        }

        public TbVdsCtlr toEntity() {
            return TbVdsCtlr.builder()
                    .vdsCtlrNmbr(this.vdsCtlrNmbr)
                    .vdsCtlrId(this.vdsCtlrId)
                    .vdsNm(this.vdsNm)
                    .vdsCtlrIp(this.vdsCtlrIp)
                    .vdsCtlrPort(this.vdsCtlrPort)
                    .vdsCtlrLocalNo(this.vdsCtlrLocalNo)
                    .vdsTypeCd(this.vdsTypeCd)
                    .istlLctnNm(this.istlLctnNm)
                    .istlLctnAddr(this.istlLctnAddr)
                    .xCrdn(this.xCrdn)
                    .yCrdn(this.yCrdn)
                    .groupNo(this.groupNo)
                    .fanMode(this.fanMode)
                    .fanRunTmpr(this.fanRunTmpr)
                    .hetrMode(this.hetrMode)
                    .hetrRunTmpr(this.hetrRunTmpr)
                    .detectLanes(this.detectLanes)
                    .trafClctCycl(this.trafClctCycl)
                    .sttsClctCycl(this.sttsClctCycl)
                    .valdYn(this.valdYn)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
