package cz.muni.fi.pa165.soccermanager.repository;

import cz.muni.fi.pa165.soccermanager.entity.Match;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface MatchRepository extends JpaRepository<Match, Long> {

  @Query("SELECT m FROM Matches m WHERE m.league.id = :leagueId")
  List<Match> findByLeagueId(Long leagueId);

  @Query("SELECT m FROM Matches m WHERE m.league.id = :leagueId AND (m.challenger.user.id = :userId OR m.defender.user.id = :userId)")
  List<Match> findMatchesByUserIdAndLeagueId(Long leagueId, Long userId);

  @Query("SELECT m FROM Matches m WHERE m.league.id = :leagueId AND (m.challenger.id = :teamId OR m.defender.id = :teamId)")
  List<Match> findMatchesByTeamIdAndLeagueId(Long teamId, Long leagueId);
}
