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.OneToOne
import jakarta.persistence.Table
import java.time.OffsetDateTime

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

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

    @Column(nullable = false, unique = true)
    var licensePlate: String = "",

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "type_id", nullable = false)
    var type: MachineTypeEntity = MachineTypeEntity(),

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "department_id", nullable = false)
    var department: DepartmentEntity = DepartmentEntity(),

    @Column(nullable = true, length = 4096)
    var description: String? = null,

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "beacon_id", nullable = true)
    var beacon: BeaconEntity? = null,

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    var lastKnownState: MachineStateCode = MachineStateCode.NO_DATA,

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