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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.link.TbLink;
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("TbLinkDto(링크정보)")
public class TbLinkDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @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("도로사용여부")  // N VARCHAR(1)
    @JsonProperty("road_use")
    private String roadUse;

    @ApiModelProperty("차로수")  // Y NUMBER(4)
    @JsonProperty("lanes")
    private Integer lanes;

    @ApiModelProperty("도로등급")  // Y VARCHAR(3)
    @JsonProperty("road_rank")
    private String roadRank;

    @ApiModelProperty("도로유형")  // Y VARCHAR(3)
    @JsonProperty("road_type")
    private String roadType;

    @ApiModelProperty("도로번호")  // Y VARCHAR(5)
    @JsonProperty("road_no")
    private String roadNo;

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

    @ApiModelProperty("중용구간여부")  // N VARCHAR(1)
    @JsonProperty("multi_link")
    private String multiLink;

    @ApiModelProperty("연결로코드")  // Y VARCHAR(3)
    @JsonProperty("link_connect")
    private String linkConnect;

    @ApiModelProperty("최고제한속도")  // Y NUMBER(4)
    @JsonProperty("max_spd")
    private Integer maxSpd;

    @ApiModelProperty("통행제한차량")  // Y VARCHAR(3)
    @JsonProperty("rest_veh")
    private String restVeh;

    @ApiModelProperty("통과제한하중")  // Y NUMBER(5)
    @JsonProperty("rest_w")
    private Integer restW;

    @ApiModelProperty("통과제한높이")  // Y NUMBER(5)
    @JsonProperty("rest_h")
    private Integer restH;

    @ApiModelProperty("연장")  // Y NUMBER(5)
    @JsonProperty("link_leng")
    private Integer linkLeng;

    @ApiModelProperty("비고")  // Y VARCHAR(50)
    @JsonProperty("rmrk")
    private String rmrk;

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

    @ApiModelProperty("디폴트 속도")  // Y NUMBER(3)
    @JsonProperty("dflt_sped")
    private Integer dfltSped;

    @ApiModelProperty("디폴트 속도 사용 여부")  // Y CHAR(1)
    @JsonProperty("dflt_sped_use_yn")
    private String dfltSpedUseYn;

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

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

    @ApiModelProperty("파라미터ID")  // Y NUMBER(10)
    @JsonProperty("para_id")
    private Long paraId;

    // Code Description Field
    @ApiModelProperty("시작노드")
    @JsonProperty("from_node")
    private String fromNodeInfo;
    @ApiModelProperty("종료노드")
    @JsonProperty("to_node")
    private String toNodeInfo;
    @ApiModelProperty("도로사용여부 설명")
    @JsonProperty("road_use_desc")
    private String roadUseDesc;
    @ApiModelProperty("도로등급 설명")
    @JsonProperty("road_rank_desc")
    private String roadRankDesc;
    @ApiModelProperty("도로유형 설명")
    @JsonProperty("road_type_desc")
    private String roadTypeDesc;
    @ApiModelProperty("중용구간여부 설명")
    @JsonProperty("multi_link_desc")
    private String multiLinkDesc;
    @ApiModelProperty("연결로코드 설명")
    @JsonProperty("link_connect_desc")
    private String linkConnectDesc;
    @ApiModelProperty("통행제한차량 설명")
    @JsonProperty("rest_veh_desc")
    private String restVehDesc;
    @ApiModelProperty("구간 등급 코드 설명")
    @JsonProperty("sect_grad_desc")
    private String sectGradDesc;

    @ApiModelProperty("시점 X 좌표")  // Y NUMBER(11,8)
    @JsonProperty("from_x_crdn")
    private Double fromXCrdn;

    @ApiModelProperty("시점 Y 좌표")  // Y NUMBER(10,8)
    @JsonProperty("from_y_crdn")
    private Double fromYCrdn;

    @ApiModelProperty("종점 X 좌표")  // Y NUMBER(11,8)
    @JsonProperty("to_x_crdn")
    private Double toXCrdn;

    @ApiModelProperty("종점 Y 좌표")  // Y NUMBER(10,8)
    @JsonProperty("to_y_crdn")
    private Double toYCrdn;

    @ApiModel("TbLinkUpdReq(링크정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbLinkUpdReq {

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

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

        @ApiModelProperty("차로수, Nullable = Y, NUMBER(4)")  // Y NUMBER(4)
        @JsonProperty("lanes")
        @PositiveOrZero
        private Integer lanes;

        @ApiModelProperty("도로등급, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("road_rank")
        @Size(min=1, max=3)
        private String roadRank;

        @ApiModelProperty("도로유형, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("road_type")
        @Size(min=1, max=3)
        private String roadType;

        @ApiModelProperty("도로번호, Nullable = Y, VARCHAR(5)")  // Y VARCHAR(5)
        @JsonProperty("road_no")
        @Size(min=1, max=5)
        private String roadNo;

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

        @ApiModelProperty("중용구간여부, Nullable = N, VARCHAR(1)")  // N VARCHAR(1)
        @JsonProperty("multi_link")
        @Size(min=1, max=1)
        private String multiLink;

        @ApiModelProperty("연결로코드, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("link_connect")
        @Size(min=1, max=3)
        private String linkConnect;

        @ApiModelProperty("최고제한속도, Nullable = Y, NUMBER(4)")  // Y NUMBER(4)
        @JsonProperty("max_spd")
        @PositiveOrZero
        private Integer maxSpd;

        @ApiModelProperty("통행제한차량, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("rest_veh")
        @Size(min=1, max=3)
        private String restVeh;

        @ApiModelProperty("통과제한하중, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("rest_w")
        @PositiveOrZero
        private Integer restW;

        @ApiModelProperty("통과제한높이, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("rest_h")
        @PositiveOrZero
        private Integer restH;

        @ApiModelProperty("연장, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("link_leng")
        @PositiveOrZero
        private Integer linkLeng;

        @ApiModelProperty("비고, Nullable = Y, VARCHAR(50)")  // Y VARCHAR(50)
        @JsonProperty("rmrk")
        @Size(min=1, max=50)
        private String rmrk;

        @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(3)")  // Y NUMBER(3)
        @JsonProperty("dflt_sped")
        @PositiveOrZero
        private Integer dfltSped;

        @ApiModelProperty("디폴트 속도 사용 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("dflt_sped_use_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String dfltSpedUseYn;

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

        @ApiModelProperty("파라미터ID, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("para_id")
        @PositiveOrZero
        private Long paraId;

        @Builder
        public TbLinkUpdReq(Long link_id, Long f_node_id, Long t_node_id, String road_use, Integer lanes, String road_rank, String road_type, String road_no, String road_name, String multi_link, String link_connect, Integer max_spd, String rest_veh, Integer rest_w, Integer rest_h, Integer link_leng, String rmrk, String del_yn, Integer dflt_sped, String dflt_sped_use_yn, String sect_grad_cd, String area_cd, Long para_id) {
            this.linkId = link_id;
            this.fNodeId = f_node_id;
            this.tNodeId = t_node_id;
            this.roadUse = road_use;
            this.lanes = lanes;
            this.roadRank = road_rank;
            this.roadType = road_type;
            this.roadNo = road_no;
            this.roadName = road_name;
            this.multiLink = multi_link;
            this.linkConnect = link_connect;
            this.maxSpd = max_spd;
            this.restVeh = rest_veh;
            this.restW = rest_w;
            this.restH = rest_h;
            this.linkLeng = link_leng;
            this.rmrk = rmrk;
            this.delYn = del_yn;
            this.dfltSped = dflt_sped;
            this.dfltSpedUseYn = dflt_sped_use_yn;
            this.sectGradCd = sect_grad_cd;
            this.areaCd = area_cd;
            this.paraId = para_id;
        }

        public TbLink toEntity() {
            return TbLink.builder()
                    .linkId(this.linkId)
                    .fNodeId(this.fNodeId)
                    .tNodeId(this.tNodeId)
                    .roadUse(this.roadUse)
                    .lanes(this.lanes)
                    .roadRank(this.roadRank)
                    .roadType(this.roadType)
                    .roadNo(this.roadNo)
                    .roadName(this.roadName)
                    .multiLink(this.multiLink)
                    .linkConnect(this.linkConnect)
                    .maxSpd(this.maxSpd)
                    .restVeh(this.restVeh)
                    .restW(this.restW)
                    .restH(this.restH)
                    .linkLeng(this.linkLeng)
                    .rmrk(this.rmrk)
                    .delYn(this.delYn)
                    .dfltSped(this.dfltSped)
                    .dfltSpedUseYn(this.dfltSpedUseYn)
                    .sectGradCd(this.sectGradCd)
                    .areaCd(this.areaCd)
                    .paraId(this.paraId)
                    .build();
        }

    }

    @ApiModel("TbLinkNameUpdReq(링크 이름변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbLinkNameUpdReq {

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

        @Builder
        public TbLinkNameUpdReq(String roadName) {
            this.roadName = roadName;
        }
    }

}
