package com.its.op.dto.its.ifsc;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.dto.its.code.TbCmmnCdDto;
import com.its.op.entity.its.ifsc.TbReptCngsSect;
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("TbReptCngsSectDto(반복 정체 구간)")
public class TbReptCngsSectDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("정보제공구간 ID")  // N NUMBER(10)
    @JsonProperty("ifsc_id")
    private Long ifscId;

    @ApiModelProperty("통계 년월")  // N VARCHAR(6)
    @JsonProperty("stat_ym")
    private String statYm;

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

    @ApiModelProperty("혼잡 시작 시분")  // N VARCHAR(4)
    @JsonProperty("cnfs_strt_hm")
    private String cnfsStrtHm;

    @ApiModelProperty("혼잡 종료 시분")  // Y VARCHAR(4)
    @JsonProperty("cnfs_end_hm")
    private String cnfsEndHm;

    @ApiModelProperty("평균 속도")  // Y NUMBER(3)
    @JsonProperty("avrg_sped")
    private Integer avrgSped;

    @ApiModelProperty("평균 통행 시간")  // Y NUMBER(6)
    @JsonProperty("avrg_trvl_hh")
    private Integer avrgTrvlHh;

    @ApiModelProperty("확정 여부")  // Y CHAR(1)
    @JsonProperty("dcsn_yn")
    private String dcsnYn;

    @ApiModelProperty("생성 일자")  // Y VARCHAR(8)
    @JsonProperty("crtn_ymd")
    private String crtnYmd;

    @ApiModelProperty("반복 정체 구간 원본 코드")  // Y VARCHAR(7)
    @JsonProperty("rept_cngs_sect_orgn_cd")
    private String reptCngsSectOrgnCd;

    // Code Description Field
    @ApiModelProperty("정보제공구간 명")  // Y VARCHAR(100)
    @JsonProperty("ifsc_nm")
    private String ifscNm;

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

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

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

    @ApiModelProperty("반복 정체 구간 원본 코드 설명")
    @JsonProperty("rept_cngs_sect_orgn_desc")    // REPT_CNGS_SECT_ORGN_CD
    private String reptCngsSectOrgnDesc;

    @ApiModel("TbReptCngsSectUpdReq(반복 정체 구간 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbReptCngsSectUpdReq {

        @ApiModelProperty("정보제공구간 ID, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("ifsc_id")
        @PositiveOrZero
        private Long ifscId;

        /*@ApiModelProperty("통계 년월, Nullable = N, VARCHAR(6)")  // N VARCHAR(6)
        @JsonProperty("stat_ym")
        @Size(min=1, max=6)*/
        @JsonIgnore
        private String statYm;

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

        @ApiModelProperty("혼잡 시작 시분, Nullable = N, VARCHAR(4)")  // N VARCHAR(4)
        @JsonProperty("cnfs_strt_hm")
        @Size(min=1, max=4)
        private String cnfsStrtHm;

        @ApiModelProperty("혼잡 종료 시분, Nullable = Y, VARCHAR(4)")  // Y VARCHAR(4)
        @JsonProperty("cnfs_end_hm")
        @Size(min=1, max=4)
        private String cnfsEndHm;

        @ApiModelProperty("평균 속도, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("avrg_sped")
        @PositiveOrZero
        private Integer avrgSped;

        @ApiModelProperty("평균 통행 시간, Nullable = Y, NUMBER(6)")  // Y NUMBER(6)
        @JsonProperty("avrg_trvl_hh")
        @PositiveOrZero
        private Integer avrgTrvlHh;

        /*@ApiModelProperty("확정 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("dcsn_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")*/
        @JsonIgnore
        private String dcsnYn;

        /*@ApiModelProperty("생성 일자, Nullable = Y, VARCHAR(8)")  // Y VARCHAR(8)
        @JsonProperty("crtn_ymd")
        @Size(min=1, max=8)*/
        @JsonIgnore
        private String crtnYmd;

       /* @ApiModelProperty("반복 정체 구간 원본 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("rept_cngs_sect_orgn_cd")
        @Size(min=1, max=7)*/
        @JsonIgnore
        private String reptCngsSectOrgnCd;

        @Builder
        public TbReptCngsSectUpdReq(Long ifsc_id, String stat_ym, String day_type_cd, String cnfs_strt_hm, String cnfs_end_hm, Integer avrg_sped, Integer avrg_trvl_hh, String dcsn_yn, String crtn_ymd, String rept_cngs_sect_orgn_cd) {
            this.ifscId = ifsc_id;
            this.statYm = stat_ym;
            this.dayTypeCd = day_type_cd;
            this.cnfsStrtHm = cnfs_strt_hm;
            this.cnfsEndHm = cnfs_end_hm;
            this.avrgSped = avrg_sped;
            this.avrgTrvlHh = avrg_trvl_hh;
            this.dcsnYn = "Y";
            this.crtnYmd = crtn_ymd;
            this.reptCngsSectOrgnCd = "RCS2";
        }

        public TbReptCngsSect toEntity() {
            return TbReptCngsSect.builder()
                    .ifscId(this.ifscId)
                    .statYm(this.statYm)
                    .dayTypeCd(this.dayTypeCd)
                    .cnfsStrtHm(this.cnfsStrtHm)
                    .cnfsEndHm(this.cnfsEndHm)
                    .avrgSped(this.avrgSped)
                    .avrgTrvlHh(this.avrgTrvlHh)
                    .dcsnYn(this.dcsnYn)
                    .crtnYmd(this.crtnYmd)
                    .reptCngsSectOrgnCd(this.reptCngsSectOrgnCd)
                    .build();
        }

    }

    @Getter
    public static class ReptCngsDayType {

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

        @ApiModelProperty("요일 유형 명")
        @JsonProperty("day_type_nm")
        private String dayTypeNm;

        @ApiModelProperty("요일 유형 설명")
        @JsonProperty("day_type_desc")
        private String dayTypeDesc;

        public ReptCngsDayType(TbCmmnCdDto entity) {
            this.dayTypeCd   = entity.getCmmnCd();
            this.dayTypeNm   = entity.getCmmnCdKorNm();
            this.dayTypeDesc = "[" + this.dayTypeCd + "]" + this.dayTypeNm;
        }
    }
}
