package com.ikon.projectmanagement.repository;

import java.util.Optional;
import java.util.UUID;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.ikon.projectmanagement.entity.FxRateEntity;

@Repository
public interface FxRateRepository extends JpaRepository<FxRateEntity, UUID> {

    @Query("SELECT f FROM FxRateEntity f LEFT JOIN FETCH f.fxRateDetails WHERE f.fxRateId = :id")
    Optional<FxRateEntity> findByIdWithDetails(@Param("id") UUID id);

    Optional<FxRateEntity> findByAccountIdentifier(UUID accountIdentifier);

    @Query("SELECT f FROM FxRateEntity f JOIN f.fxRateDetails d WHERE d.year = :year")
    Optional<FxRateEntity> findByYear(@Param("year") String year);

    @Query("SELECT f FROM FxRateEntity f JOIN f.fxRateDetails d WHERE d.year = :year AND d.currency = :currency")
    Optional<FxRateEntity> findByYearAndCurrency(@Param("year") String year, @Param("currency") String currency);
}