package com.ffii.fpsms.modules.master.entity

import com.fasterxml.jackson.annotation.JsonBackReference
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonManagedReference
import com.ffii.core.entity.BaseEntity
import jakarta.persistence.*
import jakarta.validation.constraints.NotNull

@Table(name = "bom_process")
@Entity
open class BomProcess : BaseEntity<Long>() {
    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "processId", nullable = false)
    open var process: Process? = null

    @ManyToOne
    @JoinColumn(name = "equipmentId", nullable = false)
    open var equipment: Equipment? = null

    @Column(name = "description", nullable = false)
    open var description: String? = null

//    @NotNull
//    @ManyToOne(optional = false)
//    @JoinColumn(name = "uomId", nullable = false)
//    open var uom: UomConversion? = null

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

    // in minute
    @Column(name = "durationInMinute", nullable = false)
    open var durationInMinute: Int? = null

    @Column(name = "prepTimeInMinute", nullable = false)
    open var prepTimeInMinute: Int? = null

    @Column(name = "postProdTimeInMinute", nullable = false)
    open var postProdTimeInMinute: Int? = null

    @NotNull
    @ManyToOne(optional = false)
    @JsonBackReference
    @JoinColumn(name = "bomId", nullable = false)
    open var bom: Bom? = null

    @OneToMany(mappedBy = "bomProcess", cascade = [CascadeType.ALL], orphanRemoval = true)
    @JsonManagedReference("bomProcess-material")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private val bomProcessMaterial: Set<BomProcessMaterial> = HashSet()
}