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 TruckRepository : AbstractRepository<Truck, Long> {
    
    fun findByShopIdAndDeletedFalse(shopId: Long): List<Truck>
    
    @Query("SELECT t FROM Truck t WHERE t.shop.id = :shopId AND t.deleted = false ORDER BY t.id ASC")
    fun findFirstByShopIdAndDeletedFalse(@Param("shopId") shopId: Long): List<Truck>
    
    // ✅ 使用新的 TruckLanceCode 字段名
    @Query("SELECT t FROM Truck t WHERE t.truckLanceCode = :truckLanceCode AND t.deleted = false")
    fun findByTruckLanceCodeAndDeletedFalse(@Param("truckLanceCode") truckLanceCode: String): Truck?
    

    // ✅ 按 ShopCode 查询
    @Query("SELECT t FROM Truck t WHERE t.shopCode = :shopCode AND t.deleted = false")
    fun findByShopCodeAndDeletedFalse(@Param("shopCode") shopCode: String): List<Truck>
    
    // ✅ 按 Store_id 查询
    fun findByStoreIdAndDeletedFalse(storeId: Int): List<Truck>
}