<?php

namespace Maestro\Core\Http\Controllers;

use Maestro\Core\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Spatie\Permission\Models\Permission;

class PermissionListController extends Controller
{
    /**
     * All permission names for the web guard (role editor).
     */
    public function index(Request $request): JsonResponse
    {
        abort_unless($request->user()?->can('roles.edit'), 403);

        $names = Permission::query()
            ->where('guard_name', 'web')
            ->orderBy('name')
            ->pluck('name')
            ->values();

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