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

namespace SportsDivision.Infrastructure.Repositories;

public class SchoolRepository : Repository<School>, ISchoolRepository
{
    public SchoolRepository(ApplicationDbContext context) : base(context) { }
    public override async Task<IEnumerable<School>> GetAllAsync() => await _dbSet.Include(s => s.Zone).Include(s => s.Students).OrderBy(s => s.Name).ToListAsync();
    public async Task<IEnumerable<School>> GetByZoneAsync(int zoneId) => await _dbSet.Where(s => s.ZoneId == zoneId).Include(s => s.Zone).Include(s => s.Students).OrderBy(s => s.Name).ToListAsync();
    public async Task<IEnumerable<School>> GetBySchoolLevelAsync(SchoolLevel level) => await _dbSet.Where(s => s.SchoolLevel == level).Include(s => s.Zone).Include(s => s.Students).OrderBy(s => s.Name).ToListAsync();
    public async Task<School?> GetWithStudentsAsync(int schoolId) => await _dbSet.Include(s => s.Students).Include(s => s.Zone).FirstOrDefaultAsync(s => s.SchoolId == schoolId);
}
