package space.nstart.pcp.pcp_mission_planing_service.entity

import jakarta.persistence.Column
import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import jakarta.persistence.PrePersist
import jakarta.persistence.PreUpdate
import jakarta.persistence.Table
import space.nstart.pcp.pcp_types_lib.dto.satellite.mission.ModeDataRates
import java.time.LocalDateTime

@Entity
@Table(name = "drop_modes")
@DiscriminatorValue("DROP")
class DropModeEntity(
    id: Long? = null,
    plan: PlanEntity? = null,
    timeStart: LocalDateTime? = null,
    revolution: Long = 0,

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

    @Column(name = "duration", nullable = false)
    var duration: Double = 0.0
) : ModeEntity(id, plan, timeStart, revolution) {
    /** Объём сброса, Мбайт. Денормализация: считается из duration (канал 1200 Мбит/с ÷ 8) при сохранении. */
    @Column(name = "volume_mb", nullable = false)
    var volumeMb: Double = ModeDataRates.dropVolumeMb(duration)

    @PrePersist
    @PreUpdate
    fun computeVolumeMb() {
        volumeMb = ModeDataRates.dropVolumeMb(duration)
    }
}
