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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.node.TbNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 * 노드정보 DTO Class
 */
@Data
@Builder
@ApiModel("TbNodeDto(노드정보)")
public class TbNodeDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("노드ID")  // N NUMBER(10)
    @JsonProperty("node_id")
    private Long nodeId;

    @ApiModelProperty("노드유형")  // Y VARCHAR(3)
    @JsonProperty("node_type")
    private String nodeType;

    @ApiModelProperty("교차로명칭")  // Y VARCHAR(100)
    @JsonProperty("node_name")
    private String nodeName;

    @ApiModelProperty("회전제한유무")  // Y VARCHAR(1)
    @JsonProperty("turn_p")
    private String turnP;

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

    @ApiModelProperty("X 좌표")  // Y NUMBER(11,8)
    @JsonProperty("x_crdn")
    private Double xCrdn;

    @ApiModelProperty("Y 좌표")  // Y NUMBER(10,8)
    @JsonProperty("y_crdn")
    private Double yCrdn;

    // Code Description Field
    @ApiModelProperty("노드유형 설명")
    @JsonProperty("node_type_desc")
    private String nodeTypeDesc;

    @ApiModelProperty("회전제한유무 설명")
    @JsonProperty("turn_p_desc")
    private String turnPDesc;

    @ApiModel("TbNodeUpdReq(노드정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbNodeUpdReq {

        @ApiModelProperty("노드ID, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("node_id")
        @PositiveOrZero
        private Long nodeId;

        @ApiModelProperty("노드유형, Nullable = Y, VARCHAR(3)")  // Y VARCHAR(3)
        @JsonProperty("node_type")
        @Size(min=1, max=3)
        private String nodeType;

        @ApiModelProperty("교차로명칭, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("node_name")
        @Size(min=1, max=100)
        private String nodeName;

        @ApiModelProperty("회전제한유무, Nullable = Y, VARCHAR(1)")  // Y VARCHAR(1)
        @JsonProperty("turn_p")
        @Size(min=1, max=1)
        private String turnP;

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

        @ApiModelProperty("X 좌표, , NUMBER(11,8)")  // Y NUMBER(11,8)
        @JsonProperty("x_crdn")
        private Double xCrdn;

        @ApiModelProperty("Y 좌표, , NUMBER(10,8)")  // Y NUMBER(10,8)
        @JsonProperty("y_crdn")
        private Double yCrdn;


        @Builder
        public TbNodeUpdReq(Long node_id, String node_type, String node_name, String turn_p, String rmrk, Double x_crdn, Double y_crdn) {
            this.nodeId = node_id;
            this.nodeType = node_type;
            this.nodeName = node_name;
            this.turnP = turn_p;
            this.rmrk = rmrk;
            this.xCrdn = x_crdn;
            this.yCrdn = y_crdn;
        }

        public TbNode toEntity() {
            return TbNode.builder()
                    .nodeId(this.nodeId)
                    .nodeType(this.nodeType)
                    .nodeName(this.nodeName)
                    .turnP(this.turnP)
                    .rmrk(this.rmrk)
                    .xCrdn(this.xCrdn)
                    .yCrdn(this.yCrdn)
                    .build();
        }

    }

    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbNodeNameUpdReq {

        @ApiModelProperty("교차로명칭, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("node_name")
        @Size(min=1, max=100)
        private String nodeName;

        @Builder
        public TbNodeNameUpdReq(String nodeName) {
            this.nodeName = nodeName;
        }
    }

}
