<?php

declare(strict_types=1);

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;

class UsageController extends Controller
{
    public function index()
    {
        abort_unless(auth()->user()->isAdmin(), 403);

        $users = User::query()
            ->orderBy('name')
            ->get()
            ->map(function (User $user) {
                $user->tokens_used = $user->tokensUsedThisMonth();
                $user->quota = $user->monthlyTokenQuota();

                return $user;
            });

        return view('admin.usage', ['users' => $users]);
    }
}
