package com.its.op.dto.its.road;

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

/**
 * 도로 DTO Class
 */
@Data
@Builder
@ApiModel("TbRoadDto(도로)")
public class TbRoadDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("도로 ID")  // N NUMBER(10)
    @JsonProperty("road_id")
    private Long roadId;

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

    @ApiModelProperty("방향 코드")  // Y VARCHAR(7)
    @JsonProperty("drct_cd")
    private String drctCd;

    @ApiModelProperty("시점 명")  // Y VARCHAR(100)
    @JsonProperty("strt_nm")
    private String strtNm;

    @ApiModelProperty("종점 명")  // Y VARCHAR(100)
    @JsonProperty("end_nm")
    private String endNm;

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

    @ApiModelProperty("구간 길이")  // Y NUMBER(5)
    @JsonProperty("sect_lngt")
    private Integer sectLngt;

    @ApiModelProperty("시작 노드 ID")  // Y NUMBER(10)
    @JsonProperty("f_node_id")
    private Long fNodeId;

    @ApiModelProperty("종료 노드 ID")  // Y NUMBER(10)
    @JsonProperty("t_node_id")
    private Long tNodeId;

    @ApiModelProperty("구간 등급 코드")  // Y VARCHAR(7)
    @JsonProperty("sect_grad_cd")
    private String sectGradCd;

    @ApiModelProperty("지역 코드")  // Y VARCHAR(7)
    @JsonProperty("area_cd")
    private String areaCd;

    // Code Description Field
    @ApiModelProperty("시작노드")
    @JsonProperty("from_node")
    private String fromNodeInfo;
    @ApiModelProperty("종료노드")
    @JsonProperty("to_node")
    private String toNodeInfo;

    @ApiModelProperty("방향 코드 설명")
    @JsonProperty("drct_desc")    // DRCT_CD
    private String drctDesc;

    @ApiModelProperty("구간 등급 코드 설명")
    @JsonProperty("sect_grad_desc")    // SECT_GRAD_CD
    private String sectGradDesc;

    @ApiModel("TbRoadUpdReq(도로 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbRoadUpdReq {

        @ApiModelProperty("도로 ID, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("road_id")
        @PositiveOrZero
        private Long roadId;

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

        @ApiModelProperty("방향 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("drct_cd")
        @Size(min=1, max=7)
        private String drctCd;

        @ApiModelProperty("시점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("strt_nm")
        @Size(min=1, max=100)
        private String strtNm;

        @ApiModelProperty("종점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("end_nm")
        @Size(min=1, max=100)
        private String endNm;

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

        @ApiModelProperty("구간 길이, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("sect_lngt")
        @PositiveOrZero
        private Integer sectLngt;

        @ApiModelProperty("시작 노드 ID, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("f_node_id")
        @PositiveOrZero
        private Long fNodeId;

        @ApiModelProperty("종료 노드 ID, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("t_node_id")
        @PositiveOrZero
        private Long tNodeId;

        @ApiModelProperty("구간 등급 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("sect_grad_cd")
        @Size(min=1, max=7)
        private String sectGradCd;

        @ApiModelProperty("지역 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("area_cd")
        @Size(min=1, max=7)
        private String areaCd;

        @Builder
        public TbRoadUpdReq(Long road_id, String road_nm, String drct_cd, String strt_nm, String end_nm, String del_yn, Integer sect_lngt, Long f_node_id, Long t_node_id, String sect_grad_cd, String area_cd) {
            this.roadId = road_id;
            this.roadNm = road_nm;
            this.drctCd = drct_cd;
            this.strtNm = strt_nm;
            this.endNm = end_nm;
            this.delYn = del_yn;
            this.sectLngt = sect_lngt;
            this.fNodeId = f_node_id;
            this.tNodeId = t_node_id;
            this.sectGradCd = sect_grad_cd;
            this.areaCd = area_cd;
        }

        public TbRoad toEntity() {
            return TbRoad.builder()
                    .roadId(this.roadId)
                    .roadNm(this.roadNm)
                    .drctCd(this.drctCd)
                    .strtNm(this.strtNm)
                    .endNm(this.endNm)
                    .delYn(this.delYn)
                    .sectLngt(this.sectLngt)
                    .fNodeId(this.fNodeId)
                    .tNodeId(this.tNodeId)
                    .sectGradCd(this.sectGradCd)
                    .areaCd(this.areaCd)
                    .build();
        }

    }

    @ApiModel("TbRoadNameUpdReq(도로 이름변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbRoadNameUpdReq {

        @ApiModelProperty("도로명, Nullable = Y, VARCHAR(50)")  // Y VARCHAR(50)
        @JsonProperty("road_name")
        @Size(min=1, max=50)
        private String roadName;

        @ApiModelProperty("시점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("strt_nm")
        @Size(min=1, max=100)
        private String strtNm;

        @ApiModelProperty("종점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("end_nm")
        @Size(min=1, max=100)
        private String endNm;

        @Builder
        public TbRoadNameUpdReq(String roadName, String strtNm, String endNm) {
            this.roadName = roadName;
            this.strtNm = strtNm;
            this.endNm = endNm;
        }
    }

    @ApiModel("TbRoadSectGradUpdReq(도로 구간등급 변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbRoadSectGradUpdReq {

        @ApiModelProperty("구간솥오등급, Nullable = Y, VARCHAR(7)")
        @JsonProperty("sect_grad_cd")
        @Size(min=1, max=7)
        private String sectGradCd;

        @Builder
        public TbRoadSectGradUpdReq(String sectGradCd) {
            this.sectGradCd = sectGradCd;
        }
    }

}
