package com.pressing.domain.pickup;

import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

public interface PickupRepository extends JpaRepository<Pickup, Long>, JpaSpecificationExecutor<Pickup> {
    List<Pickup> findBySiteIdAndPickupDateTimeBetween(Long siteId, LocalDateTime start, LocalDateTime end);

    // Charge invoice et invoice.customer en une seule requête (évite le N+1 sur l'historique des retraits)
    @Override
    @EntityGraph(attributePaths = {"invoice", "invoice.customer"})
    Page<Pickup> findAll(Specification<Pickup> spec, Pageable pageable);
}


