using MemberCenter.Infrastructure.Persistence;
using MemberCenter.Web.Models.Admin;
using Microsoft.EntityFrameworkCore;

namespace MemberCenter.Web.Services;

public sealed class AdminDashboardFactory
{
    private readonly MemberCenterDbContext _dbContext;

    public AdminDashboardFactory(MemberCenterDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    public async Task<AdminDashboardViewModel> BuildAsync() =>
        new()
        {
            MemberCount = await _dbContext.Users.CountAsync(),
            PendingVerificationCount = await _dbContext.Users.CountAsync(user => !user.EmailConfirmed),
            TenantCount = await _dbContext.Tenants.CountAsync(),
            NewsletterListCount = await _dbContext.NewsletterLists.CountAsync()
        };
}
