package com.ffii.fpsms.modules.pickOrder.entity

import com.ffii.core.support.AbstractRepository
import org.springframework.stereotype.Repository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import com.ffii.fpsms.modules.pickOrder.entity.projection.PickOrderGroupInfo

@Repository
interface PickOrderGroupRepository : AbstractRepository<PickOrderGroup, Long> {
    
    @Query("""
        SELECT pog FROM PickOrderGroup pog 
        WHERE pog.deleted = false 
        ORDER BY pog.name DESC
    """)
    fun findTopByOrderByNameDesc(): PickOrderGroup?
    
    @Query("""
        SELECT pog FROM PickOrderGroup pog 
        WHERE pog.pickOrderId = :pickOrderId 
        AND pog.deleted = false
    """)
    fun findByPickOrderIdAndDeletedIsFalse(@Param("pickOrderId") pickOrderId: Long): List<PickOrderGroup>
    @Query("""
    SELECT pog FROM PickOrderGroup pog 
    WHERE pog.pickOrderId IN :pickOrderIds 
    AND pog.deleted = false
""")
fun findByPickOrderIdInAndDeletedIsFalse(@Param("pickOrderIds") pickOrderIds: List<Long>): List<PickOrderGroup>
    @Query("""
        SELECT pog FROM PickOrderGroup pog 
        WHERE pog.name = :name 
        AND pog.deleted = false
    """)
    fun findByNameAndDeletedIsFalse(@Param("name") name: String): PickOrderGroup?
    @Query("""
        SELECT pog FROM PickOrderGroup pog 
        WHERE pog.deleted = false
    """)
    fun findAllByDeletedIsFalse(): List<PickOrderGroupInfo>
}