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

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

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

/**
 * 간선도로 DTO Class
 */
@Data
@Builder
@ApiModel("TbAtrdDto(간선도로)")
public class TbAtrdDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("간선도로 ID")  // N VARCHAR(10)
    @JsonProperty("atrd_id")
    private String atrdId;

    @ApiModelProperty("간선도로 명")  // Y VARCHAR(30)
    @JsonProperty("atrd_nm")
    private String atrdNm;

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

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

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

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

    private List<TbAtrdRoadRltnDto> roads = new ArrayList<>();

    @ApiModel("TbAtrdUpdReq(간선도로 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbAtrdUpdReq {

        @ApiModelProperty("간선도로 ID, Nullable = N, VARCHAR(10)")  // N VARCHAR(10)
        @JsonProperty("atrd_id")
        @Size(min=1, max=10)
        private String atrdId;

        @ApiModelProperty("간선도로 명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("atrd_nm")
        @Size(min=1, max=30)
        private String atrdNm;

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

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

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

        @ApiModelProperty("도로구성정보 목록")
        @JsonProperty("roads")
        private List<TbAtrdRoadRltnDto.TbAtrdRoadRltnUpdReq> roads;

        @Builder
        public TbAtrdUpdReq(String atrd_id, String atrd_nm, String drct_cd, String area_cd, String del_yn, List<TbAtrdRoadRltnDto.TbAtrdRoadRltnUpdReq> roads) {
            this.atrdId = atrd_id;
            this.atrdNm = atrd_nm;
            this.drctCd = drct_cd;
            this.areaCd = area_cd;
            this.delYn = del_yn;
            this.roads = roads;
        }

        public TbAtrd toEntity() {
            return TbAtrd.builder()
                    .atrdId(this.atrdId)
                    .atrdNm(this.atrdNm)
                    .drctCd(this.drctCd)
                    .areaCd(this.areaCd)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
