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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.atrd.TbAtrdRoadRltn;
import com.its.api.its.model.entity.road.TbRoad;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.PositiveOrZero;
import java.io.Serializable;

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

    @ApiModelProperty("간선도로 ID")  // N VARCHAR(10)
    @JsonProperty("atrd_id")
    private String atrdId;

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

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

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

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

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

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

    public void setRoadInfo(TbRoad road) {
        if (road != null) {
            this.roadName = road.getRoadName();
            this.strtNm = road.getStrtNm();
            this.endNm = road.getEndNm();
            this.sectLngt = road.getSectLngt();
            this.fNodeId = road.getFNodeId();
            this.tNodeId = road.getTNodeId();
        }
    }

    // Code Description Field
    @ApiModel("TbAtrdRoadRltnUpdReq(간선도로 도로 관계 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbAtrdRoadRltnUpdReq {

        /*@ApiModelProperty("간선도로 ID, Nullable = N, VARCHAR(10)")  // N VARCHAR(10)
        @JsonProperty("atrd_id")
        @Size(min=1, max=10)
        private String atrdId;*/

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

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

        @Builder
        public TbAtrdRoadRltnUpdReq(Long road_id, Integer ord) {
            this.roadId = road_id;
            this.ord = ord;
        }

        public TbAtrdRoadRltn toEntity(String atrdId) {
            return TbAtrdRoadRltn.builder()
                    .atrdId(atrdId)
                    .roadId(this.roadId)
                    .ord(this.ord)
                    .build();
        }

    }

}
