<?php

namespace App\Http\Requests\Frontend\Service;

use Illuminate\Foundation\Http\FormRequest;

final class RenameRoleRequest extends FormRequest
{
    public function authorize(): bool
    {
        return auth()->check();
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'role_id' => ['required', 'integer'],
            'new_name' => ['required', 'string', 'min:3', 'max:16', 'regex:/^[a-zA-Z0-9_]+$/'],
        ];
    }

    public function getRoleId(): int
    {
        return (int) $this->validated('role_id');
    }

    public function getNewName(): string
    {
        return trim($this->validated('new_name'));
    }
}
