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

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

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

    @ApiModelProperty("VDS 검지기 번호")  // N NUMBER(10)
    @JsonProperty("vds_dtct_nmbr")
    private Long vdsDtctNmbr;

    @ApiModelProperty("VDS 검지기 ID")  // N VARCHAR2(10)
    @JsonProperty("vds_dtct_id")
    private String vdsDtctId;

    @ApiModelProperty("VDS 검지기 명칭")  // Y VARCHAR2(40)
    @JsonProperty("vds_dtct_nm")
    private String vdsDtctNm;

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

    @ApiModelProperty("VDS 카메라 번호")  // N NUMBER(1)
    @JsonProperty("vds_cmra_no")
    private Integer vdsCmraNo;

    @ApiModelProperty("검지기 유형('DTT')")  // Y VARCHAR2(7)
    @JsonProperty("dtct_type")
    private String dtctType;

    @ApiModelProperty("검지기 방향('VCD')")  // N VARCHAR2(7)
    @JsonProperty("dtct_dir")
    private String dtctDir;

    @ApiModelProperty("검지차로(제어기설치차로)")  // Y NUMBER(2)
    @JsonProperty("detect_lane")
    private Integer detectLane;

    @ApiModelProperty("설치 차로")  // Y NUMBER(2)
    @JsonProperty("istl_lane")
    private Integer istlLane;

    @ApiModelProperty("속도수집여부")  // Y CHAR(1)
    @JsonProperty("sped_clct_yn")
    private String spedClctYn;

    @ApiModelProperty("교통량수집여부")  // Y CHAR(1)
    @JsonProperty("tfvl_clct_yn")
    private String tfvlClctYn;

    @ApiModelProperty("점유율수집여부")  // Y CHAR(1)
    @JsonProperty("ocpy_clct_yn")
    private String ocpyClctYn;

    @ApiModelProperty("최대 교통량")  // Y NUMBER(6)
    @JsonProperty("max_tfvl")
    private Integer maxTfvl;

    @ApiModelProperty("최소 교통량")  // Y NUMBER(6)
    @JsonProperty("min_tfvl")
    private Integer minTfvl;

    @ApiModelProperty("최대 점유 율")  // Y NUMBER(6,2)
    @JsonProperty("max_ocpy_rate")
    private Double maxOcpyRate;

    @ApiModelProperty("최소 점유 율")  // Y NUMBER(6,2)
    @JsonProperty("min_ocpy_rate")
    private Double minOcpyRate;

    @ApiModelProperty("최대 속도")  // Y NUMBER(3)
    @JsonProperty("max_sped")
    private Integer maxSped;

    @ApiModelProperty("최소 속도")  // Y NUMBER(3)
    @JsonProperty("min_sped")
    private Integer minSped;

    @ApiModelProperty("사용여부")  // Y CHAR(1)
    @JsonProperty("use_yn")
    private String useYn;

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

    // Code Description Field
    @ApiModelProperty("검지기 유형 코드 설명")
    @JsonProperty("dtct_type_desc")    // DTCT_TYPE_CD
    private String dtctTypeDesc;

    @ApiModelProperty("링크ID")  // N NUMBER(10)
    @JsonProperty("link_id")
    private Long linkId;

    @ApiModelProperty("속도수집여부 설명")
    @JsonProperty("sped_clct_desc")    // SPED_CLCT_YN
    private String spedClctDesc;

    @ApiModelProperty("교통량수집여부 설명")
    @JsonProperty("tfvl_clct_desc")    // TFVL_CLCT_YN
    private String tfvlClctDesc;

    @ApiModelProperty("점유율수집여부 설명")
    @JsonProperty("ocpy_clct_desc")    // OCPY_CLCT_YN
    private String ocpyClctDesc;

    @ApiModelProperty("사용여부 설명")
    @JsonProperty("use_desc")    // USE_YN
    private String useDesc;

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

    @ApiModel("TbVdsDtctUpdReq(VDS 검지기 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbVdsDtctUpdReq {

        @ApiModelProperty("VDS 검지기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("vds_dtct_nmbr")
        @Positive
        private Long vdsDtctNmbr;

        @ApiModelProperty("VDS 검지기 ID, Nullable = N, VARCHAR2(10)")  // N VARCHAR2(10)
        @JsonProperty("vds_dtct_id")
        @Size(min=1, max=10)
        private String vdsDtctId;

        @ApiModelProperty("VDS 검지기 명칭, Nullable = Y, VARCHAR2(40)")  // Y VARCHAR2(40)
        @JsonProperty("vds_dtct_nm")
        @Size(min=1, max=40)
        private String vdsDtctNm;

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

        @ApiModelProperty("VDS 카메라 번호, Nullable = N, NUMBER(1)")  // N NUMBER(1)
        @JsonProperty("vds_cmra_no")
        @Positive
        private Integer vdsCmraNo;

        @ApiModelProperty("검지기 유형('DTT'), Nullable = Y, VARCHAR2(7)")  // Y VARCHAR2(7)
        @JsonProperty("dtct_type")
        @Size(min=1, max=7)
        private String dtctType;

        @ApiModelProperty("검지기 방향('VCD'), Nullable = N, VARCHAR2(7)")  // N VARCHAR2(7)
        @JsonProperty("dtct_dir")
        @Size(min=1, max=7)
        private String dtctDir;

        @ApiModelProperty("검지차로(제어기설치차로), Nullable = Y, NUMBER(2)")  // Y NUMBER(2)
        @JsonProperty("detect_lane")
        @Positive
        private Integer detectLane;

        @ApiModelProperty("설치 차로, Nullable = Y, NUMBER(2)")  // Y NUMBER(2)
        @JsonProperty("istl_lane")
        @Positive
        private Integer istlLane;

        @ApiModelProperty("속도수집여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("sped_clct_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String spedClctYn;

        @ApiModelProperty("교통량수집여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("tfvl_clct_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String tfvlClctYn;

        @ApiModelProperty("점유율수집여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("ocpy_clct_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String ocpyClctYn;

        @ApiModelProperty("최대 교통량, Nullable = Y, NUMBER(6)")  // Y NUMBER(6)
        @JsonProperty("max_tfvl")
        @PositiveOrZero
        private Integer maxTfvl;

        @ApiModelProperty("최소 교통량, Nullable = Y, NUMBER(6)")  // Y NUMBER(6)
        @JsonProperty("min_tfvl")
        @PositiveOrZero
        private Integer minTfvl;

        @ApiModelProperty("최대 점유 율, , NUMBER(6,2)")  // Y NUMBER(6,2)
        @JsonProperty("max_ocpy_rate")
        private Double maxOcpyRate;

        @ApiModelProperty("최소 점유 율, , NUMBER(6,2)")  // Y NUMBER(6,2)
        @JsonProperty("min_ocpy_rate")
        private Double minOcpyRate;

        @ApiModelProperty("최대 속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("max_sped")
        @PositiveOrZero
        private Integer maxSped;

        @ApiModelProperty("최소 속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("min_sped")
        @PositiveOrZero
        private Integer minSped;

        @ApiModelProperty("사용여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("use_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String useYn;

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

        @ApiModelProperty("링크ID")  // N NUMBER(10)
        @JsonProperty("link_id")
        @Positive
        private Long linkId;

        @Builder
        public TbVdsDtctUpdReq(Long vds_dtct_nmbr, String vds_dtct_id, String vds_dtct_nm, Long vds_ctlr_nmbr, Integer vds_cmra_no, String dtct_type, String dtct_dir, Integer detect_lane, Integer istl_lane, String sped_clct_yn, String tfvl_clct_yn, String ocpy_clct_yn, Integer max_tfvl, Integer min_tfvl, Double max_ocpy_rate, Double min_ocpy_rate, Integer max_sped, Integer min_sped, String use_yn, String del_yn, Long linkId) {
            this.vdsDtctNmbr = vds_dtct_nmbr;
            this.vdsDtctId = vds_dtct_id;
            this.vdsDtctNm = vds_dtct_nm;
            this.vdsCtlrNmbr = vds_ctlr_nmbr;
            this.vdsCmraNo = vds_cmra_no;
            this.dtctType = dtct_type;
            this.dtctDir = dtct_dir;
            this.detectLane = detect_lane;
            this.istlLane = istl_lane;
            this.spedClctYn = sped_clct_yn;
            this.tfvlClctYn = tfvl_clct_yn;
            this.ocpyClctYn = ocpy_clct_yn;
            this.maxTfvl = max_tfvl;
            this.minTfvl = min_tfvl;
            this.maxOcpyRate = max_ocpy_rate;
            this.minOcpyRate = min_ocpy_rate;
            this.maxSped = max_sped;
            this.minSped = min_sped;
            this.useYn = use_yn;
            this.delYn = del_yn;
            this.linkId = linkId;
        }

        public TbVdsDtct toEntity() {
            String spedClctYn = this.spedClctYn == null ? "Y" : this.spedClctYn;
            String tfvlClctYn = this.tfvlClctYn == null ? "Y" : this.tfvlClctYn;
            String ocpyClctYn = this.ocpyClctYn == null ? "Y" : this.ocpyClctYn;
            String useYn = this.useYn == null ? "Y" : this.useYn;
            String delYn = this.delYn == null ? "N" : this.delYn;

            return TbVdsDtct.builder()
                    .vdsDtctNmbr(this.vdsDtctNmbr)
                    .vdsDtctId(this.vdsDtctId)
                    .vdsDtctNm(this.vdsDtctNm)
                    .vdsCtlrNmbr(this.vdsCtlrNmbr)
                    .vdsCmraNo(this.vdsCmraNo)
                    .dtctType(this.dtctType)
                    .dtctDir(this.dtctDir)
                    .detectLane(this.detectLane)
                    .istlLane(this.istlLane)
                    .spedClctYn(spedClctYn)
                    .tfvlClctYn(tfvlClctYn)
                    .ocpyClctYn(ocpyClctYn)
                    .maxTfvl(this.maxTfvl)
                    .minTfvl(this.minTfvl)
                    .maxOcpyRate(this.maxOcpyRate)
                    .minOcpyRate(this.minOcpyRate)
                    .maxSped(this.maxSped)
                    .minSped(this.minSped)
                    .useYn(useYn)
                    .delYn(delYn)
                    .build();
        }

    }

}
