<?php

declare(strict_types=1);

namespace Maestro\Core\Http\Controllers\Superadmin;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maestro\Core\Http\Controllers\Controller;
use Maestro\Core\Support\AuthUserResolver;

/**
 * Minimal user list for superadmin pickers (platform operators only).
 */
final class SuperadminUsersController extends Controller
{
    public function index(Request $request): JsonResponse
    {
        $class = AuthUserResolver::eloquentModelClass();

        $users = $class::query()
            ->orderBy('name')
            ->get(['id', 'name', 'email'])
            ->map(fn ($u) => [
                'id' => $u->id,
                'name' => $u->name,
                'email' => $u->email,
            ]);

        return response()->json(['data' => $users]);
    }
}
