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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.ifsc.TbIfsc;
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("TbIfscDto(정보제공구간)")
public class TbIfscDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

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

    @ApiModelProperty("방향 코드")  // Y VARCHAR(7)
    @JsonProperty("drct_cd")
    private String drctCd;

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

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

    @ApiModelProperty("구간 길이")  // Y NUMBER(5)
    @JsonProperty("sect_lngt")
    private Integer sectLngt;

    @ApiModelProperty("외부 연계 구간 여부")  // Y CHAR(1)
    @JsonProperty("extr_cnct_sect_yn")
    private String extrCnctSectYn;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @JsonProperty("del_yn")
    private String delYn;

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

    @ApiModelProperty("시작 노드 ID")  // Y NUMBER(10)
    @JsonProperty("f_node_id")
    private Long fNodeId;

    @ApiModelProperty("종료 노드 ID")  // Y NUMBER(10)
    @JsonProperty("t_node_id")
    private Long tNodeId;

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

    @ApiModelProperty("지역 코드")  // Y VARCHAR(7)
    @JsonProperty("area_cd")
    private String areaCd;

    // Code Description Field
    @ApiModelProperty("시작노드")
    @JsonProperty("from_node")
    private String fromNodeInfo;
    @ApiModelProperty("종료노드")
    @JsonProperty("to_node")
    private String toNodeInfo;

    @ApiModelProperty("방향 코드 설명")
    @JsonProperty("drct_desc")    // DRCT_CD
    private String drctDesc;

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

    @ApiModel("TbIfscUpdReq(정보제공구간 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbIfscUpdReq {

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

        @ApiModelProperty("정보제공구간 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("ifsc_nm")
        @Size(min=1, max=100)
        private String ifscNm;

        @ApiModelProperty("방향 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("drct_cd")
        @Size(min=1, max=7)
        private String drctCd;

        @ApiModelProperty("시점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("strt_nm")
        @Size(min=1, max=100)
        private String strtNm;

        @ApiModelProperty("종점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("end_nm")
        @Size(min=1, max=100)
        private String endNm;

        @ApiModelProperty("구간 길이, Nullable = Y, NUMBER(5)")  // Y NUMBER(5)
        @JsonProperty("sect_lngt")
        @PositiveOrZero
        private Integer sectLngt;

        @ApiModelProperty("외부 연계 구간 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("extr_cnct_sect_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String extrCnctSectYn;

        @ApiModelProperty("삭제 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("del_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String delYn;

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

        @ApiModelProperty("시작 노드 ID, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("f_node_id")
        @PositiveOrZero
        private Long fNodeId;

        @ApiModelProperty("종료 노드 ID, Nullable = Y, NUMBER(10)")  // Y NUMBER(10)
        @JsonProperty("t_node_id")
        @PositiveOrZero
        private Long tNodeId;

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

        @ApiModelProperty("지역 코드, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("area_cd")
        @Size(min=1, max=7)
        private String areaCd;

        @Builder
        public TbIfscUpdReq(Long ifsc_id, String ifsc_nm, String drct_cd, String strt_nm, String end_nm, Integer sect_lngt, String extr_cnct_sect_yn, String del_yn, String rmrk, Long f_node_id, Long t_node_id, String sect_grad_cd, String area_cd) {
            this.ifscId = ifsc_id;
            this.ifscNm = ifsc_nm;
            this.drctCd = drct_cd;
            this.strtNm = strt_nm;
            this.endNm = end_nm;
            this.sectLngt = sect_lngt;
            this.extrCnctSectYn = extr_cnct_sect_yn;
            this.delYn = del_yn;
            this.rmrk = rmrk;
            this.fNodeId = f_node_id;
            this.tNodeId = t_node_id;
            this.sectGradCd = sect_grad_cd;
            this.areaCd = area_cd;
        }

        public TbIfsc toEntity() {
            return TbIfsc.builder()
                    .ifscId(this.ifscId)
                    .ifscNm(this.ifscNm)
                    .drctCd(this.drctCd)
                    .strtNm(this.strtNm)
                    .endNm(this.endNm)
                    .sectLngt(this.sectLngt)
                    .extrCnctSectYn(this.extrCnctSectYn)
                    .delYn(this.delYn)
                    .rmrk(this.rmrk)
                    .fNodeId(this.fNodeId)
                    .tNodeId(this.tNodeId)
                    .sectGradCd(this.sectGradCd)
                    .areaCd(this.areaCd)
                    .build();
        }

    }

    @ApiModel("TbIfscNameUpdReq(정보제공구간 이름변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbIfscNameUpdReq {

        @ApiModelProperty("정보제공구간 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("ifsc_nm")
        @Size(min=1, max=100)
        private String ifscNm;

        @ApiModelProperty("시점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("strt_nm")
        @Size(min=1, max=100)
        private String strtNm;

        @ApiModelProperty("종점 명, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("end_nm")
        @Size(min=1, max=100)
        private String endNm;

        @Builder
        public TbIfscNameUpdReq(String ifscNm, String strtNm, String endNm) {
            this.ifscNm = ifscNm;
            this.strtNm = strtNm;
            this.endNm = endNm;
        }
    }

}
