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

import com.ffii.core.support.AbstractRepository
import com.ffii.fpsms.modules.master.entity.projections.BomCombo
import org.springframework.stereotype.Repository
import java.io.Serializable
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
@Repository
interface BomRepository : AbstractRepository<Bom, Long> {
    fun findAllByDeletedIsFalse(): List<Bom>

    fun findByIdAndDeletedIsFalse(id: Serializable): Bom?

    fun findByM18IdAndDeletedIsFalse(m18Id: Long): Bom?

    fun findByItemIdAndDeletedIsFalse(itemId: Serializable): Bom?

    fun findBomComboByDeletedIsFalse(): List<BomCombo>
    fun findAllByItemIdAndDeletedIsFalse(itemId: Long): List<Bom>
    fun findByCodeAndDeletedIsFalse(code: String): Bom?
    @Query("""
    select b.item.id
    from Bom b
    where b.deleted = false
      and lower(b.description) = 'wip'
      and b.item.id in :itemIds
  """)
  fun findWipItemIds(@Param("itemIds") itemIds: List<Long>): List<Long>
fun findFirstByItemIdAndDescriptionIgnoreCaseAndDeletedIsFalse(itemId: Long, description: String): Bom?
}