package com.astalange.core.repository;

import com.astalange.core.entity.AuditLogPaiement;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

@Repository
public interface AuditLogPaiementRepository extends JpaRepository<AuditLogPaiement, Long> {
    List<AuditLogPaiement> findAllByOrderByDateActionDesc();

    @Query("SELECT a FROM AuditLogPaiement a WHERE " +
           "(:action IS NULL OR :action = '' OR a.action = :action) AND " +
           "(:utilisateur IS NULL OR :utilisateur = '' OR LOWER(a.utilisateur) LIKE LOWER(CONCAT('%', :utilisateur, '%'))) AND " +
           "(:adherent IS NULL OR :adherent = '' OR LOWER(a.adherentNomComplet) LIKE LOWER(CONCAT('%', :adherent, '%'))) " +
           "ORDER BY a.dateAction DESC")
    List<AuditLogPaiement> findByFilters(
            @Param("action") String action,
            @Param("utilisateur") String utilisateur,
            @Param("adherent") String adherent
    );
}
