package com.its.op.dto.its.rse;

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

/**
 * RSE 구간 마스터 DTO Class
 */
@Data
@Builder
@ApiModel("TbRseSectDto(RSE 구간 마스터)")
public class TbRseSectDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 구간 아이디")  // N NUMBER(10)
    @JsonProperty("rse_sect_id")
    private Long rseSectId;

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

    @ApiModelProperty("RSE 구간 명")  // Y VARCHAR2(60)
    @JsonProperty("rse_sect_nm")
    private String rseSectNm;

    @ApiModelProperty("시작 지점 명")  // Y VARCHAR2(60)
    @JsonProperty("strt_spot_nm")
    private String strtSpotNm;

    @ApiModelProperty("종료 지점 명")  // Y VARCHAR2(60)
    @JsonProperty("end_spot_nm")
    private String endSpotNm;

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

    @ApiModelProperty("시작 RSE 제어기 번호")  // N NUMBER(10)
    @JsonProperty("strt_rse_ctlr_nmbr")
    private Long strtRseCtlrNmbr;

    @ApiModelProperty("종료 RSE 제어기 번호")  // N NUMBER(10)
    @JsonProperty("end_rse_ctlr_nmbr")
    private Long endRseCtlrNmbr;

    // Code Description Field
    @ApiModelProperty("삭제 여부 설명")
    @JsonProperty("del_desc")    // DEL_YN
    private String delDesc;

    @ApiModel("TbRseSectUpdReq(RSE 구간 마스터 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class TbRseSectUpdReq {

        @ApiModelProperty("RSE 구간 아이디, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("rse_sect_id")
        @PositiveOrZero
        private Long rseSectId;

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

        @ApiModelProperty("RSE 구간 명, Nullable = Y, VARCHAR2(60)")  // Y VARCHAR2(60)
        @JsonProperty("rse_sect_nm")
        @Size(min=1, max=60)
        private String rseSectNm;

        @ApiModelProperty("시작 지점 명, Nullable = Y, VARCHAR2(60)")  // Y VARCHAR2(60)
        @JsonProperty("strt_spot_nm")
        @Size(min=1, max=60)
        private String strtSpotNm;

        @ApiModelProperty("종료 지점 명, Nullable = Y, VARCHAR2(60)")  // Y VARCHAR2(60)
        @JsonProperty("end_spot_nm")
        @Size(min=1, max=60)
        private String endSpotNm;

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

        @ApiModelProperty("시작 RSE 제어기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("strt_rse_ctlr_nmbr")
        @PositiveOrZero
        private Long strtRseCtlrNmbr;

        @ApiModelProperty("종료 RSE 제어기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("end_rse_ctlr_nmbr")
        @PositiveOrZero
        private Long endRseCtlrNmbr;

        @Builder
        public TbRseSectUpdReq(Long rse_sect_id, Integer sect_lngt, String rse_sect_nm, String strt_spot_nm, String end_spot_nm, String del_yn, Long strt_rse_ctlr_nmbr, Long end_rse_ctlr_nmbr) {
            this.rseSectId = rse_sect_id;
            this.sectLngt = sect_lngt;
            this.rseSectNm = rse_sect_nm;
            this.strtSpotNm = strt_spot_nm;
            this.endSpotNm = end_spot_nm;
            this.delYn = del_yn;
            this.strtRseCtlrNmbr = strt_rse_ctlr_nmbr;
            this.endRseCtlrNmbr = end_rse_ctlr_nmbr;
        }

        public TbRseSect toEntity() {
            return TbRseSect.builder()
                    .rseSectId(this.rseSectId)
                    .sectLngt(this.sectLngt)
                    .rseSectNm(this.rseSectNm)
                    .strtSpotNm(this.strtSpotNm)
                    .endSpotNm(this.endSpotNm)
                    .delYn(this.delYn)
                    .strtRseCtlrNmbr(this.strtRseCtlrNmbr)
                    .endRseCtlrNmbr(this.endRseCtlrNmbr)
                    .build();
        }

    }

}
