package space.nstart.pcp_tgu_service.entity

/** JPA-сущность, хранящая план вместе с его процессным и подтверждающим жизненным циклом. */
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 java.util.UUID

@Entity
@Table(name = "tracked_plan")
class TrackedPlanEntity(
    @Id
    @Column(name = "plan_id", nullable = false, updatable = false)
    var planId: UUID,

    @Column(name = "spacecraft_id", nullable = false)
    var spacecraftId: String,

    @Column(name = "start_time", nullable = false)
    var startTime: LocalDateTime,

    @Column(name = "end_time", nullable = false)
    var endTime: LocalDateTime,

    @Column(name = "kpp_id", nullable = false)
    var kppId: String,

    @Column(name = "process_instance_key")
    var processInstanceKey: Long? = null,

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

    @Column(name = "confirmed_at")
    var confirmedAt: LocalDateTime? = null,

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

    @Enumerated(EnumType.STRING)
    @Column(name = "plan_source", nullable = false)
    var planSource: TrackedPlanSource = TrackedPlanSource.AUTO_CHAIN,

    @Column(name = "base_plan_id")
    var basePlanId: UUID? = null,

    @Column(name = "superseded_by_plan_id")
    var supersededByPlanId: UUID? = null
) {
    /** Создаёт пустой экземпляр сущности, необходимый для JPA. */
    constructor() : this(
        planId = UUID.randomUUID(),
        spacecraftId = "",
        startTime = LocalDateTime.MIN,
        endTime = LocalDateTime.MIN,
        kppId = ""
    )
}
