using Microsoft.EntityFrameworkCore;
using SportsDivision.Domain.Entities;
using SportsDivision.Domain.Interfaces;
using SportsDivision.Infrastructure.Data;

namespace SportsDivision.Infrastructure.Repositories;

public class RoundRepository : Repository<Round>, IRoundRepository
{
    public RoundRepository(ApplicationDbContext context) : base(context) { }
    public async Task<IEnumerable<Round>> GetByTournamentEventLevelAsync(int tournamentEventLevelId) => await _dbSet.Where(r => r.TournamentEventLevelId == tournamentEventLevelId).Include(r => r.Heats).ThenInclude(h => h.HeatLanes).OrderBy(r => r.RoundOrder).ToListAsync();
    public async Task<Round?> GetWithHeatsAsync(int roundId) => await _dbSet.Include(r => r.Heats).ThenInclude(h => h.HeatLanes).ThenInclude(hl => hl.EventRegistration).ThenInclude(er => er.Student).ThenInclude(s => s!.School).Include(r => r.TournamentEventLevel).ThenInclude(t => t.Event).Include(r => r.TournamentEventLevel).ThenInclude(t => t.EventLevel).FirstOrDefaultAsync(r => r.RoundId == roundId);
}
