package com.hpay.hpay_mobile_api.repositories;

import com.hpay.hpay_mobile_api.entities.DepotRetrait;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface DepotRetraitRepository extends JpaRepository<DepotRetrait, Integer> {

    List<DepotRetrait> findByIdClients(Integer idClients);

    List<DepotRetrait> findByIdCompte(Integer idCompte);

    List<DepotRetrait> findByNumTransaction(String numTransaction);


    @Query("SELECT d FROM DepotRetrait d " +
            "WHERE d.idClients = :idClient " +
            "AND d.typeAction = '15' "+
            "AND (:idCompte IS NULL OR d.idCompte = :idCompte) " +
            "AND (:dateStart IS NULL OR d.dateTransaction >= :dateStart) " +
            "AND (:dateEnd IS NULL OR d.dateTransaction <= :dateEnd) "

    )
    Page<DepotRetrait> searchDepots(
            Integer idClient,
            Integer idCompte,
            LocalDateTime dateStart,
            LocalDateTime dateEnd,
            Pageable pageable
    );


    @Query("SELECT d FROM DepotRetrait d " +
            "WHERE d.idClients = :idClient " +
            "AND d.typeAction = '20' "+
            "AND (:idCompte IS NULL OR d.idCompte = :idCompte) " +
            "AND (:dateStart IS NULL OR d.dateTransaction >= :dateStart) " +
            "AND (:dateEnd IS NULL OR d.dateTransaction <= :dateEnd) "

    )
    Page<DepotRetrait> searchRetraits(
            Integer idClient,
            Integer idCompte,
            LocalDateTime dateStart,
            LocalDateTime dateEnd,
            Pageable pageable
    );

}