<?php
namespace App\OpenApi;

use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\OpenApi\OpenApi;
use ApiPlatform\OpenApi\Model;

class OpenApiFactory implements OpenApiFactoryInterface
{
    public function __construct(
        private OpenApiFactoryInterface $decorated
    ) {}

    public function __invoke(array $context = []): OpenApi
    {
        $openApi = ($this->decorated)($context);

//        // Cleanup schema names
//        $schemas = $openApi->getComponents()->getSchemas();
//        $cleanedSchemas = new \ArrayObject();
//
//        foreach ($schemas as $key => $schema) {
//            // Remove the .jsonld-media_object.read suffix
//            $newKey = preg_replace('/\.jsonld-.*/', '', $key);
//            //$newKey = preg_replace('/\.jsonld-.*|\.jsonld$/', '', $key);
//            $cleanedSchemas[$newKey] = $schema;
//        }
//
//        $openApi = $openApi->withComponents(
//            $openApi->getComponents()->withSchemas($cleanedSchemas)
//        );

        return $openApi;
    }
}