package space.nstart.pcp_tgu_service.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.LocalDateTime
import space.nstart.pcp.pcp_types_lib.utils.UtcDateTimes

/**
 * Полный raw snapshot окон видимости КА из баллистики.
 *
 * payloadJson является source of truth; derived поля нужны только для диагностики.
 */
@Entity
@Table(name = "spacecraft_visibility_snapshot")
class SpacecraftVisibilitySnapshotEntity(
    @Id
    @Column(name = "spacecraft_id", nullable = false, updatable = false)
    var spacecraftId: String,

    @Column(name = "norad_id", nullable = false)
    var noradId: Long,

    @Column(name = "payload_json", nullable = false, columnDefinition = "TEXT")
    var payloadJson: String,

    @Column(name = "payload_hash", nullable = false)
    var payloadHash: String,

    @Column(name = "fetched_at", nullable = false)
    var fetchedAt: LocalDateTime,

    @Column(name = "visibility_from")
    var visibilityFrom: LocalDateTime? = null,

    @Column(name = "visibility_to")
    var visibilityTo: LocalDateTime? = null,

    @Column(name = "windows_count")
    var windowsCount: Int? = null,

    @Column(name = "created_at", nullable = false)
    var createdAt: LocalDateTime = UtcDateTimes.now(),

    @Column(name = "updated_at", nullable = false)
    var updatedAt: LocalDateTime = UtcDateTimes.now()
) {
    /** Создаёт пустой экземпляр сущности, необходимый для JPA. */
    constructor() : this(spacecraftId = "", noradId = 0, payloadJson = "", payloadHash = "", fetchedAt = LocalDateTime.MIN)
}
