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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.ifsc.TbIfsc;
import com.its.api.its.model.entity.vms.TbVmsLinkIfsc;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.PositiveOrZero;
import java.io.Serializable;

/**
 * VMS LINK 정보제공구간 DTO Class
 */
@Data
@Builder
@ApiModel("TbVmsLinkIfscDto(VMS LINK 정보제공구간)")
public class TbVmsLinkIfscDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

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

    @ApiModelProperty("순서")  // Y NUMBER(3)
    @JsonProperty("ord")
    private Integer ord;

    // 정보제공구간 부가 정보
    @ApiModelProperty("정보제공구간 명")
    @JsonProperty("ifsc_nm")
    private String ifscNm;

    @ApiModelProperty("정보제공구간 시점 명")
    @JsonProperty("strt_nm")
    private String strtNm;

    @ApiModelProperty("정보제공구간 종점 명")
    @JsonProperty("end_nm")
    private String endNm;

    public void setIfscInfo(TbIfsc ifsc) {
        if (ifsc == null) {
            this.ifscNm = "";
            this.strtNm = "";
            this.endNm  = "";
        }
        else {
            this.ifscNm = ifsc.getIfscNm();
            this.strtNm = ifsc.getStrtNm();
            this.endNm  = ifsc.getEndNm();
        }
    }
    // Code Description Field
    @ApiModel("TbVmsLinkIfscUpdReq(VMS LINK 정보제공구간 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbVmsLinkIfscUpdReq {

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

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

        @ApiModelProperty("순서, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("ord")
        @PositiveOrZero
        private Integer ord;

        @Builder
        public TbVmsLinkIfscUpdReq(Long vms_ifsc_id, Long ifsc_id, Integer ord) {
            this.vmsIfscId = vms_ifsc_id;
            this.ifscId = ifsc_id;
            this.ord = ord;
        }

        public TbVmsLinkIfsc toEntity() {
            return TbVmsLinkIfsc.builder()
                    .vmsIfscId(this.vmsIfscId)
                    .ifscId(this.ifscId)
                    .ord(this.ord)
                    .build();
        }

    }

}
