package space.nstart.pcp_tgu_service.entity

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

/**
 * Job на перечитывание окон видимости одного КА у баллистики.
 */
@Entity
@Table(name = "visibility_refresh_job")
class VisibilityRefreshJobEntity(
    @Id
    @Column(name = "spacecraft_id", nullable = false, updatable = false)
    var spacecraftId: String,

    @Column(name = "norad_id")
    var noradId: Long? = null,

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    var status: JobStatus = JobStatus.PENDING,

    @Column(name = "reason")
    var reason: String? = null,

    @Column(name = "locked_by")
    var lockedBy: String? = null,

    @Column(name = "locked_until")
    var lockedUntil: LocalDateTime? = null,

    @Column(name = "attempts", nullable = false)
    var attempts: Int = 0,

    @Column(name = "rerun_requested", nullable = false)
    var rerunRequested: Boolean = false,

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

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