<?php

declare(strict_types=1);

namespace App\Http\Requests\Collections;

use App\Services\CollectionLinkService;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'entity_links' => ['nullable', 'array', 'max:18'],
            'entity_links.*.linked_type' => ['required', 'string', Rule::in(CollectionLinkService::supportedTypes())],
            'entity_links.*.linked_id' => ['required', 'integer', 'min:1'],
            'entity_links.*.relationship_type' => ['nullable', 'string', 'max:80'],
        ];
    }
}
