<?php

namespace App\Http\Controllers\Api\V1\Admin\User;

use App\Models\AdminRole;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Support\AdminRoleApiPresenter;
final class AdminRoleIndexController extends Controller
{
    public function __invoke(): JsonResponse
    {
        $roles = AdminRole::query()
            ->where('scope_type', AdminRole::SCOPE_SYSTEM)
            ->orderBy('sort_order')
            ->orderBy('id')
            ->get();

        return ApiResponse::success([
            'items' => $roles->map(static fn (AdminRole $role): array => AdminRoleApiPresenter::item($role))->values()->all(),
        ]);
    }
}
