<?php

namespace App\Http\Requests\Authz;

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

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

    public function rules(): array
    {
        $tenantId = (int) app('tenant_id');
        $guard = 'api';

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