<?php

namespace App\Http\Requests\Identity;

class UpdateRoleRequest extends StoreRoleRequest
{
    public function rules(): array
    {
        $rules = parent::rules();
        $rules['label'] = ['sometimes', 'string', 'max:120'];
        unset($rules['name']); // A role's key is immutable once assigned to users.

        return $rules;
    }

    /** @return array<string, string>|null null = leave existing grants alone. */
    public function grants(): ?array
    {
        return $this->has('permissions') ? (array) $this->input('permissions') : null;
    }
}
