package com.its.op.dto.its.vms;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.vms.TbVmsIfsc;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.List;

/**
 * VMS 정보제공구간 DTO Class
 */
@Data
@Builder
@ApiModel("TbVmsIfscDto(VMS 정보제공구간)")
public class TbVmsIfscDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 정보제공구간 ID")  // N NUMBER(10)
    @JsonProperty("vms_ifsc_id")
    private Long vmsIfscId;

    @ApiModelProperty("VMS 정보제공구간 명")  // Y VARCHAR(60)
    @JsonProperty("vms_ifsc_nm")
    private String vmsIfscNm;

    @ApiModelProperty("표출 시작 노드 명")  // Y VARCHAR(30)
    @JsonProperty("dspl_strt_node_nm")
    private String dsplStrtNodeNm;

    @ApiModelProperty("표출 종료 노드 명")  // Y VARCHAR(30)
    @JsonProperty("dspl_end_node_nm")
    private String dsplEndNodeNm;

    @ApiModelProperty("우회도로 ID")  // Y NUMBER(10)
    @JsonProperty("detr_id")
    private Long detrId;

    @ApiModelProperty("도로명")  // Y VARCHAR(30)
    @JsonProperty("road_nm")
    private String roadNm;

    @ApiModelProperty("지점명")  // Y VARCHAR(30)
    @JsonProperty("spot_nm")
    private String spotNm;

    @ApiModelProperty("축정보 생성용")  // Y CHAR(1)
    @JsonProperty("axis_yn")
    private String axisYn;
    @ApiModelProperty("사용 여부")  // Y CHAR(1)
    @JsonProperty("use_yn")
    private String useYn;

    @ApiModelProperty("정체폼생성시 정체판정기준속도")  // Y NUMBER(3)
    @JsonProperty("cngs_spd")
    private Integer cngsSpd;

    // Code Description Field
    //@ApiModelProperty("편집 코드 설명")
    //@JsonProperty("edtn_desc")    // EDTN_CD
    //private String edtnDesc;

    @ApiModelProperty("원활")
    @JsonProperty("grad1")
    private TbVmsIfscCmtrGradDto.CmtrGrad grad1;
    @ApiModelProperty("지체")
    @JsonProperty("grad2")
    private TbVmsIfscCmtrGradDto.CmtrGrad grad2;
    @ApiModelProperty("정체")
    @JsonProperty("grad3")
    private TbVmsIfscCmtrGradDto.CmtrGrad grad3;

    @ApiModelProperty("정보제공구간 목록")
    @JsonProperty("ifscs")
    List<TbVmsIfscRltnIfscDto> ifscs;

    @ApiModel("TbVmsIfscUpdReq(VMS 정보제공구간 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbVmsIfscUpdReq {

        @ApiModelProperty("VMS 정보제공구간 ID, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("vms_ifsc_id")
        @PositiveOrZero
        private Long vmsIfscId;

        @ApiModelProperty("VMS 정보제공구간 명, Nullable = Y, VARCHAR(60)")  // Y VARCHAR(60)
        @JsonProperty("vms_ifsc_nm")
        @Size(min=1, max=60)
        private String vmsIfscNm;

        @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, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("dspl_strt_node_nm")
        @Size(min=1, max=30)
        private String dsplStrtNodeNm;

        @ApiModelProperty("표출 종료 노드 명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("dspl_end_node_nm")
        @Size(min=1, max=30)
        private String dsplEndNodeNm;

        @ApiModelProperty("우회도로 ID-없음=0, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("detr_id")
        @Min(value = 0)
        @Max(value = Long.MAX_VALUE)
        private Long detrId;

        @ApiModelProperty("도로명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("road_nm")
        @Size(min=1, max=30)
        private String roadNm;

        @ApiModelProperty("지점명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("spot_nm")
        @Size(min=1, max=30)
        private String spotNm;

        @ApiModelProperty("축정보 생성용, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("axis_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String axisYn;

        @ApiModelProperty("정체폼생성시 정체판정기준속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("cngs_spd")
        @PositiveOrZero
        private Integer cngsSpd;

        @ApiModelProperty("원활")
        @JsonProperty("grad1")
        private TbVmsIfscCmtrGradDto.CmtrGrad grad1;
        @ApiModelProperty("지체")
        @JsonProperty("grad2")
        private TbVmsIfscCmtrGradDto.CmtrGrad grad2;
        @ApiModelProperty("정체")
        @JsonProperty("grad3")
        private TbVmsIfscCmtrGradDto.CmtrGrad grad3;

        @ApiModelProperty("정보제공구간 목록")
        @JsonProperty("ifscs")
        private List<VmsIfscLinkOrd> ifscs;

        @Builder
        public TbVmsIfscUpdReq(Long vms_ifsc_id, String vms_ifsc_nm, String useYn, String dspl_strt_node_nm,
                               String dspl_end_node_nm, Long detr_id, String road_nm, String spot_nm, String axis_yn, Integer cngs_spd,
                               TbVmsIfscCmtrGradDto.CmtrGrad grad1, TbVmsIfscCmtrGradDto.CmtrGrad grad2, TbVmsIfscCmtrGradDto.CmtrGrad grad3,
                               List<VmsIfscLinkOrd> ifscs) {
            this.vmsIfscId = vms_ifsc_id;
            this.vmsIfscNm = vms_ifsc_nm;
            this.useYn = useYn;
            this.dsplStrtNodeNm = dspl_strt_node_nm;
            this.dsplEndNodeNm = dspl_end_node_nm;
            this.detrId = detr_id;
            this.roadNm = road_nm;
            this.spotNm = spot_nm;
            this.axisYn = axis_yn;
            this.cngsSpd = cngs_spd;
            this.grad1 = grad1;
            this.grad2 = grad2;
            this.grad3 = grad3;

            // FOR KISA Secure Coding pass
            //this.ifscs = ifscs;
            List<VmsIfscLinkOrd> temp = ifscs;
            this.ifscs = temp;
        }

        public TbVmsIfsc toEntity() {
            return TbVmsIfsc.builder()
                    .vmsIfscId(this.vmsIfscId)
                    .vmsIfscNm(this.vmsIfscNm)
                    .dsplStrtNodeNm(this.dsplStrtNodeNm)
                    .dsplEndNodeNm(this.dsplEndNodeNm)
                    .detrId(this.detrId)
                    .roadNm(this.roadNm)
                    .spotNm(this.spotNm)
                    .axisYn(this.axisYn)
                    .useYn(this.useYn)
                    .cngsSpd(this.cngsSpd)
                    .build();
        }

    }

    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class VmsIfscLinkOrd {
        @ApiModelProperty("정보제공구간 ID")  // N NUMBER(10)
        @JsonProperty("ifsc_id")
        private Long ifscId;

        @ApiModelProperty("순서")  // Y NUMBER(3)
        @JsonProperty("ord")
        private Integer ord;

//        @Builder
//        public VmsIfscLinkOrd(Long ifsc_id, Integer ord) {
//            this.ifscId = ifsc_id;
//            this.ord = ord;
//        }
    }

}
