<?php

declare(strict_types=1);

namespace App\Framework\Database\Metadata;

final class MetadataRegistry
{
    private array $metadata = [];

    public function __construct(
        private readonly MetadataExtractor $extractor
    ) {
    }

    public function getMetadata(string $entityClass): EntityMetadata
    {
        if (! isset($this->metadata[$entityClass])) {
            $this->metadata[$entityClass] = $this->extractor->extractMetadata($entityClass);
        }

        return $this->metadata[$entityClass];
    }

    public function hasMetadata(string $entityClass): bool
    {
        return isset($this->metadata[$entityClass]);
    }

    public function clearCache(): void
    {
        $this->metadata = [];
    }
}
