using Microsoft.EntityFrameworkCore;
using MTWorkHR.Core.Entities;
using MTWorkHR.Core.IDto;
using MTWorkHR.Core.IRepositories;
using MTWorkHR.Infrastructure.Entities;
using MTWorkHR.Infrastructure.DBContext;

namespace MTWorkHR.Infrastructure.Repositories
{
    public class TeamRepository : Repository<Team>, ITeamRepository
    {
        private readonly DbSet<Team> dbSet;

        public TeamRepository(HRDataContext context) : base(context)
        {
            dbSet = context.Set<Team>();

        }
        public async Task<Team> GetByIdWithAllChildren(long id)
        {
            return await dbSet
                .Include(x => x.TeamUsers)
                .FirstOrDefaultAsync(x => x.Id == id);
        }
        public  async  Task<Tuple<IQueryable<Team>, int>> GetAllWithChildrenAsync()
        {
            var query = dbSet.Include(x => x.TeamUsers).AsQueryable();
            var total = await query.CountAsync();

            return new Tuple<IQueryable<Team>, int>(query, total);
        }
    }
}