<?php

declare(strict_types=1);

namespace App\Http\Requests\Groups;

use App\Models\Group;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateGroupMemberPermissionsRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    public function rules(): array
    {
        return [
            'permission_overrides' => ['required', 'array'],
            'permission_overrides.*.key' => ['required', 'string', Rule::in(Group::permissionKeys())],
            'permission_overrides.*.is_allowed' => ['nullable', 'boolean'],
        ];
    }
}