package com.astalange.core.repository;

import com.astalange.core.entity.Paiement;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;

@Repository
public interface PaiementRepository extends JpaRepository<Paiement, Long> {

    @Query("SELECT SUM(p.montant) FROM Paiement p")
    BigDecimal sumMontant();

    @Query("SELECT p FROM Paiement p " +
           "LEFT JOIN FETCH p.licence l " +
           "LEFT JOIN FETCH l.adherent a " +
           "LEFT JOIN FETCH l.categorie c " +
           "LEFT JOIN FETCH p.modePaiement m " +
           "ORDER BY p.datePaiement DESC, p.id DESC")
    java.util.List<Paiement> findAllWithAssociations();
}
