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

namespace SportsDivision.Infrastructure.Repositories;

public class HeatLaneRepository : Repository<HeatLane>, IHeatLaneRepository
{
    public HeatLaneRepository(ApplicationDbContext context) : base(context) { }

    public async Task<IEnumerable<HeatLane>> GetByHeatAsync(int heatId) =>
        await _dbSet.Where(l => l.HeatId == heatId)
            .Include(l => l.EventRegistration)
                .ThenInclude(r => r.Student!)
                    .ThenInclude(s => s.School)
            .OrderBy(l => l.LaneNumber)
            .ToListAsync();

    public async Task<HeatLane?> GetWithDetailsAsync(int heatLaneId) =>
        await _dbSet
            .Include(l => l.EventRegistration)
                .ThenInclude(r => r.Student!)
                    .ThenInclude(s => s.School)
            .FirstOrDefaultAsync(l => l.HeatLaneId == heatLaneId);
}
