package space.nstart.pcp.pcp_stations_service.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
import space.nstart.pcp.pcp_types_lib.dto.ballistics.PositionDTO
import space.nstart.pcp.pcp_types_lib.dto.ballistics.StationDTO
import java.util.UUID

@Entity
@Table(name = "stations")
class StationEntity(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val stationId : UUID? = null,
    @Column(nullable = false)
    val number : Int = 0,
    @Column(nullable = false)
    val name : String = "",
    @Column(nullable = false)
    val longitude : Double = 0.0,
    @Column(nullable = false)
    val latitude : Double = 0.0,
    @Column(nullable = false)
    val height : Double = 0.0,
    @Column(name = "elevation_min", nullable = false)
    val elevationMin : Double = 0.0,
    @Column(name = "elevation_max", nullable = false)
    val elevationMax : Double = 0.0,
){
    constructor(s : StationDTO) : this(
        s.id,
        s.number,
        s.name,
        s.position.long,
        s.position.lat,
        s.position.height,
        s.elevationMin,
        s.elevationMax
    )

    fun toDTO() = StationDTO(
        stationId,
        number,
        name,
        PositionDTO(latitude, longitude, height),
        elevationMin,
        elevationMax
    )
}
