<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Client;
use App\Models\Domain;
use App\Models\Employee;
use App\Models\Invoice;
use App\Models\Project;
use App\Models\Server;
use App\Support\DashboardData;
use Illuminate\View\View;

class ReportsController extends Controller
{
    public function __invoke(): View
    {
        $dashboard = DashboardData::build();

        return view('reports.index', [
            'stats' => $dashboard['stats'],
            'clientsCount' => Client::query()->count(),
            'invoicesCount' => Invoice::query()->count(),
            'employeesCount' => Employee::query()->count(),
            'serversCount' => Server::query()->count(),
            'domainsCount' => Domain::query()->count(),
            'projectsCount' => Project::query()->count(),
            'monthlyServerCost' => (float) Server::query()->sum('cost'),
        ]);
    }
}
