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> {
    
    @Query("SELECT t FROM Truck t WHERE t.shop.id = :shopId AND t.deleted = false")
    fun findByShopIdAndDeletedFalse(@Param("shopId") 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> // ✅ Change to List<Truck>
    
    @Query("SELECT t FROM Truck t WHERE t.truckNo = :truckNo AND t.deleted = false")
    fun findByTruckNoAndDeletedFalse(@Param("truckNo") truckNo: String): Truck?
    
    @Query("SELECT t FROM Truck t WHERE t.status = :status AND t.deleted = false")
    fun findByStatusAndDeletedFalse(@Param("status") status: String): List<Truck>
}