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

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

import javax.validation.constraints.PositiveOrZero;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

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

    @ApiModelProperty("VMS 제어기 번호")  // N NUMBER(10)
    @JsonProperty("vms_ctlr_nmbr")
    private Long vmsCtlrNmbr;

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

    @ApiModelProperty("표출 우선순위")  // Y NUMBER(2)
    @JsonProperty("dspl_prrt")
    private Integer dsplPrrt;

    @ApiModelProperty("VMS 정보제공구간 명")  // Y VARCHAR(60)
    @JsonProperty("vms_ifsc_nm")
    private String vmsIfscNm;

    @ApiModelProperty("표출 시작 노드 명")  // Y VARCHAR(30)
    @JsonProperty("dspl_strt_node_nm")
    private String dsplStrtNodeNm;

    @ApiModelProperty("표출 종료 노드 명")  // Y VARCHAR(30)
    @JsonProperty("dspl_end_node_nm")
    private String dsplEndNodeNm;

    @ApiModel("VmsIfscRltn(VMS 정보제공구간 관계 정보)")
    @Getter
    @Setter
    @ToString
    public static class VmsIfscRltn {

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

        @ApiModelProperty("표출 우선순위, Nullable = Y, NUMBER(2)")  // Y NUMBER(2)
        @JsonProperty("dspl_prrt")
        @PositiveOrZero
        private Integer dsplPrrt;
    }

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

        @ApiModelProperty("VMS 제어기 번호, Nullable = N, NUMBER(10)")  // N NUMBER(10)
        @JsonProperty("vms_ctlr_nmbr")
        @PositiveOrZero
        private Long vmsCtlrNmbr;

        @ApiModelProperty("VMS 정보제공구간 목록")
        @JsonProperty("ifscs")
        List<VmsIfscRltn> ifscs;

        @Builder
        public TbVmsIfscRltnUpdReq(Long vms_ctlr_nmbr, List<VmsIfscRltn> ifscs) {
            this.vmsCtlrNmbr = vms_ctlr_nmbr;
            this.ifscs = ifscs;
        }

        public List<TbVmsIfscRltn> toEntity() {
            List<TbVmsIfscRltn> result = new ArrayList<>();
            if (this.ifscs != null) {
                for (VmsIfscRltn rltn : this.ifscs) {
                    result.add(TbVmsIfscRltn.builder()
                            .vmsCtlrNmbr(this.vmsCtlrNmbr)
                            .vmsIfscId(rltn.getVmsIfscId())
                            .dsplPrrt(rltn.getDsplPrrt())
                            .build());
                }
            }
            return result;
        }

    }

}
