package com.its.op.dto.its.vms;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.vms.TbVmsRltnIfsc;
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("TbVmsRltnIfscDto(VMS 정보제공구간 관계)")
public class TbVmsRltnIfscDto implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("VMS ID")  // Y VARCHAR(4)
    @JsonProperty("vms_id")
    private String vmsId;

    @ApiModelProperty("VMS 제어기 ID")  // Y VARCHAR(30)
    @JsonProperty("vms_ctlr_id")
    private String vmsCtlrId;

    @ApiModelProperty("VMS 명")  // Y VARCHAR(40)
    @JsonProperty("vms_nm")
    private String vmsNm;

    @ApiModelProperty("VMS 유형 코드")  // Y VARCHAR(7)
    @JsonProperty("vms_type_cd")
    private String vmsTypeCd;

    @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;

    @ApiModelProperty("도로명")  // Y VARCHAR(30)
    @JsonProperty("road_nm")
    private String roadNm;

    @ApiModelProperty("지점명")  // Y VARCHAR(30)
    @JsonProperty("spot_nm")
    private String spotNm;

    @ApiModelProperty("축정보 생성용")  // Y CHAR(1)
    @JsonProperty("axis_yn")
    private String axisYn;

    @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;

            // FOR KISA Secure Coding pass
            //this.ifscs = ifscs;
            List<VmsIfscRltn> temp = ifscs;
            this.ifscs = temp;
        }

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

    }

}
