using Insight.Infrastructure;
using Insight.Infrastructure.Entities;
using Insight.Web.Constants;
using Microsoft.AspNetCore.Components;
using MongoDB.Driver;
using MudBlazor;

namespace Insight.Web.Pages.Management.Overview;

[Route(Navigation.Management.Overview.Index)]
public partial class Index
{
    [Inject] private IMongoDatabase Database { get; init; } = default!;
    [Inject] private ISnackbar Snackbar { get; init; } = default!;

    private readonly string _title = "Management｜Insight";
    private readonly List<BreadcrumbItem> _breadcrumbs = new()
    {
        new BreadcrumbItem("Home", href: Navigation.Home),
        new BreadcrumbItem("Management", href: "#", true)
    };

    private async Task LoadDataAsync()
    {
        try
        {
            _accounts = await Database.User().CountDocumentsAsync(Builders<InsightUser>.Filter.Empty, cancellationToken: default).ConfigureAwait(false);
            _customers = await Database.Customer().CountDocumentsAsync(Builders<CustomerEntity>.Filter.Empty, cancellationToken: default).ConfigureAwait(false);
            _hosts = await Database.Host().CountDocumentsAsync(Builders<HostEntity>.Filter.Empty, cancellationToken: default).ConfigureAwait(false);
            _agents = await Database.Agent().CountDocumentsAsync(Builders<AgentEntity>.Filter.Empty, cancellationToken: default).ConfigureAwait(false);
        }
        catch (Exception)
        {
            Notification.Error(Snackbar);
        }
    }
}