package com.ffii.fpsms.modules.productProcess.entity
import com.fasterxml.jackson.annotation.JsonBackReference
import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.entity.Equipment
import com.ffii.fpsms.modules.master.entity.Items
import com.ffii.fpsms.modules.user.entity.User
import jakarta.persistence.*
import jakarta.validation.constraints.Size

import java.time.LocalDateTime
import com.ffii.fpsms.modules.master.entity.BomProcess
@Entity
@Table(name = "productprocessline")
open class ProductProcessLine : BaseEntity<Long>() {
    

    //  添加 @ManyToOne
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operatorId")
    open var operator: User? = null
    
    //  添加 @ManyToOne
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "equipmentId")
    open var equipment: Equipment? = null

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

    @Size(max = 100)
    @Column(name = "name", length = 100)
    open var name: String? = null
    
    @Column(name = "description")
    open var description: String? = null
    
    @Size(max = 100)
    @Column(name = "equipment_name", length = 100)
    open var equipmentType: String? = null
    
    @Column(name = "processingTime")
    open var processingTime: Int? = null
    @Column(name = "setupTime")
    open var setupTime: Int? = null
    @Column(name = "changeoverTime")
    open var changeoverTime: Int? = null
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "byproductId")
    open var byproduct: Items? = null
    @Column(name = "status")
    open var status: String? = null
    @Size(max = 100)
    @Column(name = "byproductName", length = 100)
    open var byproductName: String? = null
    
    @Column(name = "byproductQty", precision = 16, scale = 2)
    open var byproductQty: Int? = null
    
    @Size(max = 20)
    @Column(name = "byproductUom", length = 20)
    open var byproductUom: String? = null
    
    @Column(name = "scrapQty", precision = 16, scale = 2)
    open var scrapQty: Int? = null
    
    @Size(max = 20)
    @Column(name = "scrapUom", length = 20)
    open var scrapUom: String? = null
    
    @Column(name = "defectQty", precision = 16, scale = 2)
    open var defectQty: Int? = null
    
    @Size(max = 20)
    @Column(name = "defectUom", length = 20)
    open var defectUom: String? = null
    
    @Column(name = "defectDescription", length = 255)
    open var defectDescription: String? = null
    
    @Column(name = "defectQty2", precision = 16, scale = 2)
    open var defectQty2: Int? = null
    
    @Column(name = "defectDescription2", length = 255)
    open var defectDescription2: String? = null
    
    @Column(name = "defectUom2", length = 20)
    open var defectUom2: String? = null
    
    @Column(name = "defectQty3", precision = 16, scale = 2)
    open var defectQty3: Int? = null
    
    @Column(name = "defectUom3", length = 20)
    open var defectUom3: String? = null
    
    @Column(name = "defectDescription3", length = 255)
    open var defectDescription3: String? = null
    
    @Column(name = "outputFromProcessQty", precision = 16, scale = 2)
    open var outputFromProcessQty: Int? = null
    
    @Size(max = 20)
    @Column(name = "outputFromProcessUom", length = 20)
    open var outputFromProcessUom: String? = null
    
    @Column(name = "startTime")
    open var startTime: LocalDateTime? = null
    @Column(name = "is_original")
    open var isOriginal: Boolean? = null
    @Column(name = "endTime")
    open var endTime: LocalDateTime? = null
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bomProcessId")
    open var bomProcess: BomProcess? = null
    @Column(name = "seqNo")
    open var seqNo: Long? = null
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "handlerId")
    open var handler: User? = null
    @JsonBackReference
    @ManyToOne
    @JoinColumn(name = "productprocessid", nullable = false)
    open var productProcess: ProductProcess = ProductProcess()
    data class ProductProcessLineDetail(
        val id: Long?,
        val name: String?,
        val description: String?,
        val equipmentType: String?,
        val status: String?,
        val byproduct: Items?,
        val byproductName: String?,
        val byproductQty: Int?,
        val byproductUom: String?,
        val scrapQty: Int?,
        val scrapUom: String?,
    )
}