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

import com.its.api.its.model.dto.parking.ParkingLotDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 *  Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("")
@Entity
@Table(name = "PARKINGLOT")
public class ParkingLot implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("")  // N VARCHAR(10)
    @Id
    @Column(name = "PARKINGID", nullable = false, length = 10)
    private String parkingId;

    @ApiModelProperty("")  // Y VARCHAR(50)
    @Column(name = "PARKINGNAME", length = 50)
    private String parkingName;

    @ApiModelProperty("")  // Y VARCHAR(120)
    @Column(name = "LOCATION", length = 120)
    private String location;

    @ApiModelProperty("")  // Y VARCHAR(100)
    @Column(name = "ADDRESS", length = 100)
    private String address;

    @ApiModelProperty("")  // Y VARCHAR(20)
    @Column(name = "PHONE", length = 20)
    private String phone;

    @ApiModelProperty("")  // Y NUMBER(3)
    @Column(name = "PARKINGCNT", columnDefinition = "NUMBER", length = 3)
    private Integer parkingCnt;

    @ApiModelProperty("")  // Y NUMBER(0)
    @Column(name = "COORDX", columnDefinition = "NUMBER", length = 11, precision = 8)
    private Double coordx;

    @ApiModelProperty("")  // Y NUMBER(0)
    @Column(name = "COORDY", columnDefinition = "NUMBER", length = 10, precision = 8)
    private Double coordy;

    @ApiModelProperty("")  // Y CHAR(1)
    @Column(name = "PISFLAG", columnDefinition = "CHAR", length = 1)
    private String pisFlag;

    @ApiModelProperty("")  // Y VARCHAR(5)
    @Column(name = "DISTRICTID", length = 5)
    private String districtId;

    @ApiModelProperty("")  // Y VARCHAR(30)
    @Column(name = "PARKINGENAME", length = 30)
    private String parkingEName;

    @ApiModelProperty("")  // Y VARCHAR(128)
    @Column(name = "ELOCATION", length = 128)
    private String eLocation;

    @ApiModelProperty("")  // Y VARCHAR(100)
    @Column(name = "EADDRESS", length = 100)
    private String eAddress;

    public ParkingLotDto toDto() {
        return ParkingLotDto.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)
                .pisFlag(this.pisFlag)
                .districtId(this.districtId)
                .build();
    }

    public void updateInfo(ParkingLotDto.ParkingLotUpdReq req) {
        this.parkingId = req.getParkingId();
        this.parkingName = req.getParkingName();
        this.location = req.getLocation();
        this.address = req.getAddress();
        this.phone = req.getPhone();
        this.parkingCnt = req.getParkingCnt();
        this.coordx = req.getCoordx();
        this.coordy = req.getCoordy();
        this.pisFlag = req.getPisFlag();
        this.districtId = req.getDistrictId();
        this.parkingEName = req.getParkingEName();
        this.eLocation = req.getELocation();
        this.eAddress = req.getEAddress();
    }

}
