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

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.parking.ParkingLot;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 *  DTO Class
 */
@Data
@Builder
@ApiModel("ParkingLotDto(주차장)")
public class ParkingLotDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("주차장 ID")  // N VARCHAR(10)
    @JsonProperty("parkingid")
    private String parkingId;

    @ApiModelProperty("주차장명")  // Y VARCHAR(50)
    @JsonProperty("parkingname")
    private String parkingName;

    @ApiModelProperty("위치")  // Y VARCHAR(120)
    @JsonProperty("location")
    private String location;

    @ApiModelProperty("주소")  // Y VARCHAR(100)
    @JsonProperty("address")
    private String address;

    @ApiModelProperty("전화번호")  // Y VARCHAR(20)
    @JsonProperty("phone")
    private String phone;

    @ApiModelProperty("주차면수")  // Y NUMBER(3)
    @JsonProperty("parkingcnt")
    private Integer parkingCnt;

    @ApiModelProperty("위치X")  // Y NUMBER(0)
    @JsonProperty("coordx")
    private Double coordx;

    @ApiModelProperty("위치Y")  // Y NUMBER(0)
    @JsonProperty("coordy")
    private Double coordy;

    @ApiModelProperty("주차정보플래그")  // Y CHAR(1)
    @JsonProperty("pisflag")
    //@JsonIgnore
    private String pisFlag;

    @ApiModelProperty("지역ID")  // Y VARCHAR(5)
    @JsonProperty("districtid")
    //@JsonIgnore
    private String districtId;

    @ApiModelProperty("영문명")  // Y VARCHAR(30)
    @JsonProperty("parkingename")
    private String parkingEName;

    @ApiModelProperty("영문위치")  // Y VARCHAR(128)
    @JsonProperty("elocation")
    private String eLocation;

    @ApiModelProperty("영문주소")  // Y VARCHAR(100)
    @JsonProperty("eaddress")
    private String eAddress;

    // Code Description Field
    @ApiModel("ParkinglotUpdReq(주차장 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class ParkingLotUpdReq {

        @ApiModelProperty("주차장 ID, Nullable = N, VARCHAR(10)")  // N VARCHAR(10)
        @JsonProperty("parkingid")
        @Size(min=1, max=10)
        private String parkingId;

        @ApiModelProperty("주차장명, Nullable = Y, VARCHAR(50)")  // Y VARCHAR(50)
        @JsonProperty("parkingname")
        @Size(min=1, max=50)
        private String parkingName;

        @ApiModelProperty("위치, Nullable = Y, VARCHAR(120)")  // Y VARCHAR(120)
        @JsonProperty("location")
        @Size(min=1, max=120)
        private String location;

        @ApiModelProperty("주소, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("address")
        @Size(min=1, max=100)
        private String address;

        @ApiModelProperty("전화번호, Nullable = Y, VARCHAR(20)")  // Y VARCHAR(20)
        @JsonProperty("phone")
        @Size(min=1, max=20)
        private String phone;

        @ApiModelProperty("주차면수, Nullable = Y, NUMBER(3)")  // Y NUMBER(3)
        @JsonProperty("parkingcnt")
        @PositiveOrZero
        private Integer parkingCnt;

        @ApiModelProperty("위치X, Nullable = Y, NUMBER(11,8)")  // Y NUMBER(0)
        @JsonProperty("coordx")
        @PositiveOrZero
        private Double coordx;

        @ApiModelProperty("위치Y, Nullable = Y, NUMBER(10,8)")  // Y NUMBER(0)
        @JsonProperty("coordy")
        @PositiveOrZero
        private Double coordy;

        //@ApiModelProperty("주차정보플래그, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        //@JsonProperty("pisflag")
        //@Size(min=1, max=1)
        //@Pattern(regexp = "[YN]")
        @JsonIgnore
        private String pisFlag;

        //@ApiModelProperty("지역ID, Nullable = Y, VARCHAR(5)")  // Y VARCHAR(5)
        //@JsonProperty("districtid")
        //@Size(min=1, max=5)
        @JsonIgnore
        private String districtId;

        @ApiModelProperty("영문명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("parkingename")
        @Size(min=1, max=30)
        private String parkingEName;

        @ApiModelProperty("영문위치, Nullable = Y, VARCHAR(128)")  // Y VARCHAR(128)
        @JsonProperty("elocation")
        @Size(min=1, max=128)
        private String eLocation;

        @ApiModelProperty("영문주소, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("eaddress")
        @Size(min=1, max=100)
        private String eAddress;

        @Builder
        public ParkingLotUpdReq(String parkingId, String parkingname, String location, String address, String phone, Integer parkingCnt, Double coordx, Double coordy, String pisFlag, String districtId, String parkingEName, String eLocation, String eAddress) {
            this.parkingId = parkingId;
            this.parkingName = parkingname;
            this.location = location;
            this.address = address;
            this.phone = phone;
            this.parkingCnt = parkingCnt;
            this.coordx = coordx;
            this.coordy = coordy;
            this.pisFlag = pisFlag;
            this.districtId = districtId;
            this.parkingEName = parkingEName;
            this.eLocation = eLocation;
            this.eAddress = eAddress;
        }

        public ParkingLot toEntity() {
            return ParkingLot.builder()
                    .parkingId(this.parkingId)
                    .parkingName(this.parkingName)
                    .location(this.location)
                    .address(this.address)
                    .phone(this.phone)
                    .parkingCnt(this.parkingCnt)
                    .coordx(this.coordx)
                    .coordy(this.coordy)
                    .pisFlag(this.pisFlag)
                    .districtId(this.districtId)
                    .parkingEName(this.parkingEName)
                    .eLocation(this.eLocation)
                    .eAddress(this.eAddress)
                    .build();
        }

    }

}
