<?php
declare(strict_types=1);

namespace App\Modules\Admin;

use App\Core\Database;
use App\Core\Request;
use App\Core\View;

final class AdminUserController
{
    public function index(Request $request): string
    {
        require_role('admin');

        $users = Database::query(
            'SELECT id, nama, email, whatsapp, role, created_at, updated_at
             FROM users
             ORDER BY created_at DESC, id DESC'
        )->fetchAll();

        return View::renderTemplate('admin/users', [
            'users' => $users,
        ], 'admin/layout');
    }
}
