<?php

namespace App\Http\Requests\Authz;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class RoleUpdateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $tenantId = (int) app('tenant_id');
        $guard = 'api';
        $roleId = (int) $this->route('id');

        return [
            'name' => [
                'sometimes', 'string', 'max:100',
                Rule::unique('roles', 'name')
                    ->where(fn ($q) => $q->where('tenant_id', $tenantId)->where('guard_name', $guard))
                    ->ignore($roleId),
            ],
            'description' => 'sometimes|nullable|string|max:255',
            'is_hidden' => 'sometimes|boolean',
        ];
    }
}
