<?php

declare (strict_types=1);
namespace PoPSchema\DirectiveCommons\DirectiveResolvers;

use PoPSchema\DirectiveCommons\FeedbackItemProviders\FeedbackItemProvider;
use PoPSchema\DirectiveCommons\ObjectModels\TypedDataValidationPayload;
use PoPSchema\SchemaCommons\TypeResolvers\ScalarType\EmailScalarTypeResolver;
use PoPSchema\SchemaCommons\TypeResolvers\ScalarType\HTMLScalarTypeResolver;
use PoPSchema\SchemaCommons\TypeResolvers\ScalarType\URLAbsolutePathScalarTypeResolver;
use PoPSchema\SchemaCommons\TypeResolvers\ScalarType\URLScalarTypeResolver;
use PoP\ComponentModel\Feedback\FeedbackItemResolution;
use PoP\ComponentModel\TypeResolvers\ConcreteTypeResolverInterface;
use PoP\ComponentModel\TypeResolvers\RelationalTypeResolverInterface;
use PoP\ComponentModel\TypeResolvers\ScalarType\AnyBuiltInScalarScalarTypeResolver;
use PoP\ComponentModel\TypeResolvers\ScalarType\AnyStringScalarScalarTypeResolver;
use PoP\ComponentModel\TypeResolvers\ScalarType\IDScalarTypeResolver;
use PoP\ComponentModel\TypeResolvers\ScalarType\StringScalarTypeResolver;
use PoP\GraphQLParser\Spec\Parser\Ast\FieldInterface;
/** @internal */
abstract class AbstractTransformStringFieldValueFieldDirectiveResolver extends \PoPSchema\DirectiveCommons\DirectiveResolvers\AbstractTransformTypedFieldValueFieldDirectiveResolver
{
    /**
     * @return array<class-string<ConcreteTypeResolverInterface>>|null
     */
    protected function getSupportedFieldTypeResolverClasses() : ?array
    {
        return [StringScalarTypeResolver::class, IDScalarTypeResolver::class, AnyBuiltInScalarScalarTypeResolver::class, AnyStringScalarScalarTypeResolver::class, EmailScalarTypeResolver::class, HTMLScalarTypeResolver::class, URLAbsolutePathScalarTypeResolver::class, URLScalarTypeResolver::class];
    }
    protected function isMatchingType(mixed $value) : bool
    {
        return \is_string($value);
    }
    /**
     * @param string $value
     * @return mixed TypedDataValidationPayload if error, or the value otherwise
     */
    protected final function transformTypeValue(mixed $value) : mixed
    {
        return $this->transformStringValue($value);
    }
    protected abstract function transformStringValue(string $value) : string|TypedDataValidationPayload;
    /**
     * Validate the value against the directive args
     *
     * @param string $value
     */
    protected final function validateTypeData(mixed $value) : ?TypedDataValidationPayload
    {
        return $this->validateParams() ?? $this->validateStringData($value);
    }
    protected function validateStringData(string $value) : ?TypedDataValidationPayload
    {
        return null;
    }
    protected function validateParams() : ?TypedDataValidationPayload
    {
        return null;
    }
    protected function getNonMatchingTypeValueFeedbackItemResolution(mixed $value, string|int $id, FieldInterface $field, RelationalTypeResolverInterface $relationalTypeResolver) : FeedbackItemResolution
    {
        return new FeedbackItemResolution(FeedbackItemProvider::class, FeedbackItemProvider::E2, [$this->getDirectiveName(), $field->getOutputKey(), $id]);
    }
}
