package com.ffii.fpsms.modules.pickOrder.entity

import com.ffii.core.entity.BaseEntity
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.time.LocalDateTime

@Entity
@Table(name = "truck_lane_schedule")
open class TruckLaneSchedule : BaseEntity<Long>() {

    @NotNull
    @Column(name = "executeAt", nullable = false)
    open var executeAt: LocalDateTime? = null

    @field:NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    open var status: TruckLaneScheduleStatus = TruckLaneScheduleStatus.PENDING

    @field:NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "source", nullable = false, length = 20)
    open var source: TruckLaneScheduleSource = TruckLaneScheduleSource.MANUAL

    @field:Size(max = 500)
    @Column(name = "note", length = 500)
    open var note: String? = null

    @Column(name = "appliedAt")
    open var appliedAt: LocalDateTime? = null

    @field:Size(max = 2000)
    @Column(name = "errorMessage", length = 2000)
    open var errorMessage: String? = null

    @Column(name = "snapshotVersionId")
    open var snapshotVersionId: Long? = null

    @Column(name = "preApplySnapshotVersionId")
    open var preApplySnapshotVersionId: Long? = null

    @OneToMany(mappedBy = "schedule", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var lines: MutableList<TruckLaneScheduleLine> = mutableListOf()
}
