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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.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.ArrayList;
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(7)
    @JsonProperty("edtn_cd")
    private String edtnCd;

    @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;

    // 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<TbVmsLinkIfscDto> ifscs = new ArrayList<>();

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

        @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("정체")
        @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;

        @Getter
        @Setter
        @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 TbVmsIfscUpdReq(Long vms_ifsc_id, String vms_ifsc_nm, String edtn_cd, String dspl_strt_node_nm, String dspl_end_node_nm, Long detr_id, String road_nm, String spot_nm, String axis_yn) {
            this.vmsIfscId = vms_ifsc_id;
            this.vmsIfscNm = vms_ifsc_nm;
            this.edtnCd = edtn_cd;
            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;
        }

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

    }

}
