package llc.arma.fleet.monitor.data.entity

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import java.time.OffsetDateTime

@Entity
@Table(name = "machine_state_intervals")
class MachineStateIntervalEntity(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "machine_id", nullable = false)
    var machine: MachineEntity = MachineEntity(),

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "state_definition_id", nullable = true)
    var stateDefinition: MachineStateDefinitionEntity? = null,

    @Enumerated(EnumType.STRING)
    @Column(nullable = true)
    var stateCode: MachineStateCode? = null,

    @Column(nullable = false)
    var startedAt: OffsetDateTime = OffsetDateTime.now(),

    @Column(nullable = true)
    var endedAt: OffsetDateTime? = null,

    @Column(nullable = false)
    var durationSeconds: Int = 0,

    @Column(nullable = true)
    var vibrationMin: Double? = null,

    @Column(nullable = true)
    var vibrationMax: Double? = null,

    @Column(nullable = true)
    var vibrationAvg: Double? = null,

    @Column(nullable = false)
    var sampleCount: Int = 0,

    @Column(nullable = false)
    var isNoData: Boolean = false,
) : BaseEntity()
