package com.its.op.dto.its.code;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.code.TbSectGradStup;
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("TbCmtrGradClsfDto(소통 등급 분류)")
public class TbCmtrGradClsfDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("소통 등급 코드")  // N VARCHAR(7)
    @JsonProperty("cmtr_grad_cd")
    private String cmtrGradCd;

    @ApiModelProperty("최저 통행 속도")  // Y NUMBER(3)
    @JsonProperty("lwst_trvl_sped")
    private Integer lwstTrvlSped;

    @ApiModelProperty("최고 통행 속도")  // Y NUMBER(3)
    @JsonProperty("hghs_trvl_sped")
    private Integer hghsTrvlSped;

    @ApiModelProperty("정체 등급 여부")  // Y CHAR(1)
    @JsonProperty("cngs_grad_yn")
    private String cngsGradYn;

    // Code Description Field
    @ApiModelProperty("구간 등급 코드 설명")
    @JsonProperty("sect_grad_desc")    // SECT_GRAD_CD
    private String sectGradDesc;

    @ApiModelProperty("소통 등급 코드 설명")
    @JsonProperty("cmtr_grad_desc")    // CMTR_GRAD_CD
    private String cmtrGradDesc;

    @ApiModel("TbCmtrGradClsfUpdReq(소통 등급 분류 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbCmtrGradClsfUpdReq {

        @ApiModelProperty("구간 등급 코드, Nullable = N, VARCHAR(7)")  // N VARCHAR(7)
        @JsonProperty("sect_grad_cd")
        @Size(min=1, max=7)
        private String sectGradCd;

        @ApiModelProperty("소통 등급 코드, Nullable = N, VARCHAR(7)")  // N VARCHAR(7)
        @JsonProperty("cmtr_grad_cd")
        @Size(min=1, max=7)
        private String cmtrGradCd;

        @ApiModelProperty("최저 통행 속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("lwst_trvl_sped")
        @PositiveOrZero
        private Integer lwstTrvlSped;

        @ApiModelProperty("최고 통행 속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("hghs_trvl_sped")
        @PositiveOrZero
        private Integer hghsTrvlSped;

        @ApiModelProperty("정체 등급 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("cngs_grad_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String cngsGradYn;

        @Builder
        public TbCmtrGradClsfUpdReq(String sect_grad_cd, String cmtr_grad_cd, Integer lwst_trvl_sped, Integer hghs_trvl_sped, String cngs_grad_yn) {
            this.sectGradCd = sect_grad_cd;
            this.cmtrGradCd = cmtr_grad_cd;
            this.lwstTrvlSped = lwst_trvl_sped;
            this.hghsTrvlSped = hghs_trvl_sped;
            this.cngsGradYn = cngs_grad_yn;
        }

        public TbSectGradStup toEntity() {
            return TbSectGradStup.builder()
                    .sectGradCd(this.sectGradCd)
                    .cmtrGradCd(this.cmtrGradCd)
                    .lwstTrvlSped(this.lwstTrvlSped)
                    .hghsTrvlSped(this.hghsTrvlSped)
                    .cngsGradYn(this.cngsGradYn)
                    .build();
        }

    }

}
