package com.ffii.fpsms.modules.productProcess.entity
import com.fasterxml.jackson.annotation.JsonManagedReference
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.jobOrder.entity.JobOrder
import com.ffii.fpsms.modules.master.entity.Items
import com.ffii.fpsms.modules.productProcess.enums.ProductProcessStatus
import com.ffii.fpsms.modules.productProcess.enums.ProductProcessStatusConverter
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.time.LocalDate
import java.time.LocalDateTime
import com.ffii.fpsms.modules.master.entity.Bom
@Entity
@Table(name = "productprocess")
open class ProductProcess : BaseEntity<Long>() {

    @Size(max = 50)
    @NotNull
    @Column(name = "productprocesscode", nullable = false, unique = true, length = 50)
    open var productProcessCode: String? = null
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "jobOrderId")
    open var jobOrder: JobOrder? = null

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "itemsId")
    open var item: Items? = null

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bomId", nullable = false)
    open var bom: Bom? = null
    
    @NotNull
    @Column(name = "status", nullable = false, length = 20)
    @Convert(converter = ProductProcessStatusConverter::class)
    open var status: ProductProcessStatus = ProductProcessStatus.PENDING
    
    @Column(name = "startTime")
    open var startTime: LocalDateTime? = null
    
    @Column(name = "endTime")
    open var endTime: LocalDateTime? = null
    
    @Column(name = "date")
    open var date: LocalDate? = null
    
    @JsonManagedReference
    @OneToMany(mappedBy = "productProcess", cascade = [CascadeType.ALL], orphanRemoval = true)
    open var productionScheduleLines: MutableList<ProductProcessLine> = mutableListOf()

    @Column(name = "productionPriority")
    open var productionPriority: Int? = 50
    
    @Column(name = "submitedBagRecord")
    open var submitedBagRecord: Boolean? = false
    
}