package com.mvrent.carrental.repository;

import com.mvrent.carrental.model.CarDocument;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface CarDocumentRepository extends JpaRepository<CarDocument, Long> {

    /** Documents already expired or expiring on/before the given cut-off date. */
    @Query("""
            SELECT d FROM CarDocument d
            WHERE d.expiryDate IS NOT NULL AND d.expiryDate <= :cutoff
            ORDER BY d.expiryDate ASC
            """)
    List<CarDocument> findExpiringOrExpired(@Param("cutoff") LocalDate cutoff);
}
