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

import com.ffii.core.support.AbstractRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository

@Repository
interface RouterRepository : AbstractRepository<Router, Long> {
    
    @Query("SELECT r FROM Router r WHERE r.inventoryLotId = :inventoryLotId AND r.deleted = false")
    fun findByInventoryLotIdAndDeletedFalse(@Param("inventoryLotId") inventoryLotId: Int): List<Router>
    
    @Query("SELECT r FROM Router r WHERE r.inventoryLotId = :inventoryLotId AND r.deleted = false ORDER BY r.id ASC")
    fun findFirstByInventoryLotIdAndDeletedFalse(@Param("inventoryLotId") inventoryLotId: Int): Router?
    
    @Query("SELECT r FROM Router r WHERE r.itemCode = :itemCode AND r.deleted = false")
    fun findByItemCodeAndDeletedFalse(@Param("itemCode") itemCode: Int): List<Router>
    
    @Query("SELECT r FROM Router r WHERE r.route = :route AND r.deleted = false")
    fun findByRouteAndDeletedFalse(@Param("route") route: Int): List<Router>
    
    @Query("SELECT r FROM Router r WHERE r.routerId = :routerId AND r.deleted = false")
    fun findByRouterIdAndDeletedFalse(@Param("routerId") routerId: Int): List<Router>
}