package com.its.op.dto.its.link;

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

/**
 * 링크 15분 통계 DTO Class
 */
@Data
@Builder
@ApiModel("TbLinkStat15mDto(링크 15분 통계)")
public class TbLinkStat15mDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("통계 일시")  // N VARCHAR(14)
    @JsonProperty("stat_dt")
    private String statDt;

    @ApiModelProperty("요일 유형 코드")  // Y VARCHAR(7)
    @JsonProperty("day_type_cd")
    private String dayTypeCd;

    @ApiModelProperty("교통량")  // Y NUMBER(6)
    @JsonProperty("tfvl")
    private Integer tfvl;

    @ApiModelProperty("속도")  // Y NUMBER(3)
    @JsonProperty("sped")
    private Integer sped;

    @ApiModelProperty("점유 율")  // Y NUMBER(5,2)
    @JsonProperty("ocpy_rate")
    private Double ocpyRate;

    @ApiModelProperty("통행 시간")  // Y NUMBER(6)
    @JsonProperty("trvl_hh")
    private Integer trvlHh;

    @ApiModelProperty("데이터 개수")  // Y NUMBER(3)
    @JsonProperty("data_num")
    private Integer dataNum;

    // Code Description Field
    @ApiModelProperty("요일 유형 코드 설명")
    @JsonProperty("day_type_desc")    // DAY_TYPE_CD
    private String dayTypeDesc;

    @ApiModel("TbLink15mStatUpdReq(링크 15분 통계 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbLink15mStatUpdReq {

        @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("stat_dt")
        @Size(min=1, max=14)
        private String statDt;

        @ApiModelProperty("요일 유형 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("day_type_cd")
        @Size(min=1, max=7)
        private String dayTypeCd;

        @ApiModelProperty("교통량, Nullable = Y, NUMBER(6)")  // Y NUMBER(6)
        @JsonProperty("tfvl")
        @PositiveOrZero
        private Integer tfvl;

        @ApiModelProperty("속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("sped")
        @PositiveOrZero
        private Integer sped;

        @ApiModelProperty("점유 율, , NUMBER(5,2)")  // Y NUMBER(5,2)
        @JsonProperty("ocpy_rate")
        private Double ocpyRate;

        @ApiModelProperty("통행 시간, Nullable = Y, NUMBER(6)")  // Y NUMBER(6)
        @JsonProperty("trvl_hh")
        @PositiveOrZero
        private Integer trvlHh;

        @ApiModelProperty("데이터 개수, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("data_num")
        @PositiveOrZero
        private Integer dataNum;

        @Builder
        public TbLink15mStatUpdReq(Long link_id, String stat_dt, String day_type_cd, Integer tfvl, Integer sped, Double ocpy_rate, Integer trvl_hh, Integer data_num) {
            this.linkId = link_id;
            this.statDt = stat_dt;
            this.dayTypeCd = day_type_cd;
            this.tfvl = tfvl;
            this.sped = sped;
            this.ocpyRate = ocpy_rate;
            this.trvlHh = trvl_hh;
            this.dataNum = data_num;
        }

        public TbLinkStat15m toEntity() {
            return TbLinkStat15m.builder()
                    .linkId(this.linkId)
                    .statDt(this.statDt)
                    .dayTypeCd(this.dayTypeCd)
                    .tfvl(this.tfvl)
                    .sped(this.sped)
                    .ocpyRate(this.ocpyRate)
                    .trvlHh(this.trvlHh)
                    .dataNum(this.dataNum)
                    .build();
        }

    }

}
