<?php

declare(strict_types=1);

namespace App\GraphQL\Schema\Fields\Wiki\ExternalResource;

use App\Contracts\GraphQL\Fields\CreatableField;
use App\Contracts\GraphQL\Fields\UpdatableField;
use App\GraphQL\Filter\IntFilter;
use App\GraphQL\Schema\Fields\IntField;
use App\Models\Wiki\ExternalResource;

class ExternalResourceExternalIdField extends IntField implements CreatableField, UpdatableField
{
    public function __construct()
    {
        parent::__construct(ExternalResource::ATTRIBUTE_EXTERNAL_ID);
    }

    public function description(): string
    {
        return 'The primary key of the resource in the external site';
    }

    public function getFilter(): IntFilter
    {
        return new IntFilter($this->name(), $this->getColumn())
            ->useEq();
    }

    /**
     * @param  array<string, mixed>  $args
     */
    public function getCreationRules(array $args): array
    {
        return [
            'nullable',
            'string',
            'max:65535',
        ];
    }

    /**
     * @param  array<string, mixed>  $args
     */
    public function getUpdateRules(array $args): array
    {
        return [
            'nullable',
            'string',
            'max:65535',
        ];
    }
}
