package space.nstart.pcp.complan.types

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import io.swagger.v3.oas.annotations.media.Schema
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.io.WKTReader
import java.time.LocalDateTime
import java.util.*

@Schema(description = "Объект каталога для планирования")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize
data class AplObjItem(

    @get:JsonProperty("name")
    @param:JsonProperty("name")
    val name: String,

    @get:JsonProperty("geometry")
    @param:JsonProperty("geometry")
    val geometry: Geometry,

    @get:JsonProperty("id")
    @param:JsonProperty("id")
    val id : UUID,

    @get:JsonProperty("intevals")
    @param:JsonProperty("intevals")
    @JsonIgnore
    val intevals : MutableList<IntervalItemDTO>,

    @get:JsonProperty("krenMin")
    @param:JsonProperty("krenMin")
    val krenMin : Double,

    @get:JsonProperty("krenMax")
    @param:JsonProperty("krenMax")
    val krenMax : Double,

    @get:JsonProperty("intervalBegin")
    @param:JsonProperty("intervalBegin")
    val intervalBegin : LocalDateTime? = null,

    @get:JsonProperty("intervalEnd")
    @param:JsonProperty("intervalEnd")
    val intervalEnd : LocalDateTime? = null,

    @get:JsonProperty("lastChange")
    @param:JsonProperty("lastChange")
    /** Если значение данного параметра null, значит задание новое */
    val lastChange : LocalDateTime? = null,
) {
    constructor(obj: RequestItemDTO) : this(
        name = obj.name,
        geometry = WKTReader().read(obj.geometry),
        id = obj.id,
        intevals = mutableListOf(),
        krenMin = -45.0,
        krenMax = 45.0
    )
}
