package space.nstart.pcp.pcp_request_service.entity

import space.nstart.pcp.pcp_request_service.utils.UtcDateTimes
import ballistics.utils.toDateTime
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.RevolutionSign
import space.nstart.pcp.pcp_types_lib.dto.ballistics.SquareViewParamDTO
import java.time.LocalDateTime
import kotlin.math.PI

@Entity
@Table(name = "cell_covering")
class EarthCellViewsEntity(
    @Id
    @Column(name = "cell_covering_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id : Long? = null,
    @Column(nullable = false)
    val satelliteId : Long = 0,
    @Column(nullable = false)
    val cellNum : Long = 0,
    @Column(name = "rev_begin", nullable = false)
    val revolutionBegin : Long = 0,
    @Column(nullable = false)
    val timeBegin : LocalDateTime = UtcDateTimes.now(),
    @Column(nullable = false)
    val revSignBegin : Int = 0,
    @Column(name = "rev_end", nullable = false)
    val revolutionEnd: Long = 0,
    @Column(nullable = false)
    val timeEnd : LocalDateTime = UtcDateTimes.now(),
    @Column(nullable = false)
    val revSignEnd : Int = 0,
    @Column(name = "roll_min")
    val gammaMin : Double = 0.0,
    @Column(name = "roll_max")
    val gammaMax : Double = 0.0,
    @Column(name = "contour_wkt", nullable = false)
    val contour : String = ""
) {

    fun toDTO() =         SquareViewParamDTO(
        this.satelliteId,
        this.cellNum.toString(),
        this.revolutionBegin,
        this.timeBegin,
        if (this.revSignBegin == 0) RevolutionSign.ASC else RevolutionSign.DESC,
        this.revolutionBegin,
        this.timeEnd,
        if (this.revSignEnd == 0) RevolutionSign.ASC else RevolutionSign.DESC,
        this.gammaMin,
        this.gammaMax
    )
}
