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

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

@Entity
@Table(name = "qc_category")
open class QcCategory : BaseEntity<Long>() {
    @NotNull
    @Column(name = "code")
    open var code: String? = null

    @NotNull
    @Column(name = "name")
    open var name: String? = null

    @NotNull
    @Column(name = "description")
    open var description: String? = null

    @NotNull
    @Column(name = "isDefault")
    open var isDefault: Boolean = false

//    @OneToMany(cascade = [CascadeType.ALL])
//    @JoinTable(
//        name = "qc_item_category",
//        joinColumns = [JoinColumn(name = "qcCategoryId")],
//        inverseJoinColumns = [JoinColumn(name = "qcItemId")]
//    )
//    open var qcItems: MutableList<QcItem> = mutableListOf()

    @JsonManagedReference
    @OneToMany(mappedBy = "qcCategory", cascade = [CascadeType.ALL], orphanRemoval = true)
    @com.fasterxml.jackson.annotation.JsonIgnore
    open var qcItemCategory: MutableList<QcItemCategory> = mutableListOf()
}

@Entity
@Table(name = "items_qc_category_mapping")
open class ItemsQcCategoryMapping : IdEntity<Long>() {
    @NotNull
    @Column(name = "itemId")
    open var itemId: Long? = null

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

    @NotNull
    @Column(name = "type")
    open var type: String? = null
//
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "qcCategoryId")
//    val qcCategory: QcCategory? = null
}