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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.incident.TbIncdEstmSect;
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("TbIncdEstmSectDto(돌발상황 예상 구간)")
public class TbIncdEstmSectDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("검지 일시")  // N VARCHAR(14)
    @JsonProperty("detc_dt")
    private String detcDt;

    @ApiModelProperty("수집 속도 평균")  // Y NUMBER(3)
    @JsonProperty("clct_sped_avrg")
    private Integer clctSpedAvrg;

    @ApiModelProperty("예상 속도 평균")  // Y NUMBER(3)
    @JsonProperty("estm_sped_avrg")
    private Integer estmSpedAvrg;

    @ApiModelProperty("사실 여부")  // Y CHAR(1)
    @JsonProperty("real_yn")
    private String realYn;

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

    @ApiModelProperty("시작노드")
    @JsonProperty("from_node")
    private String fromNodeInfo;

    @ApiModelProperty("종료노드")
    @JsonProperty("to_node")
    private String toNodeInfo;

    @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("real_desc")    // REAL_YN
    private String realDesc;

    @ApiModel("TbIncdEstmSectUpdReq(돌발상황 예상 구간 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbIncdEstmSectUpdReq {

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

        @ApiModelProperty("검지 일시, Nullable = N, VARCHAR(14)")  // N VARCHAR(14)
        @JsonProperty("detc_dt")
        @Size(min=1, max=14)
        private String detcDt;

        @ApiModelProperty("수집 속도 평균, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("clct_sped_avrg")
        @PositiveOrZero
        private Integer clctSpedAvrg;

        @ApiModelProperty("예상 속도 평균, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("estm_sped_avrg")
        @PositiveOrZero
        private Integer estmSpedAvrg;

        @ApiModelProperty("사실 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("real_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String realYn;

        @Builder
        public TbIncdEstmSectUpdReq(Long link_id, String detc_dt, Integer clct_sped_avrg, Integer estm_sped_avrg, String real_yn) {
            this.linkId = link_id;
            this.detcDt = detc_dt;
            this.clctSpedAvrg = clct_sped_avrg;
            this.estmSpedAvrg = estm_sped_avrg;
            this.realYn = real_yn;
        }

        public TbIncdEstmSect toEntity() {
            return TbIncdEstmSect.builder()
                    .linkId(this.linkId)
                    .detcDt(this.detcDt)
                    .clctSpedAvrg(this.clctSpedAvrg)
                    .estmSpedAvrg(this.estmSpedAvrg)
                    .realYn(this.realYn)
                    .build();
        }

    }

}
