<?php

declare(strict_types=1);

namespace App\Framework\Reflection\Strategies;

use App\Framework\Core\ValueObjects\ClassName;
use App\Framework\Reflection\ReflectionCache;

/**
 * Strategy for warming up reflection caches
 */
final readonly class CacheWarmupStrategy
{
    public function __construct(
        private ReflectionCache $cache
    ) {
    }

    /**
     * Warm up cache with commonly used framework classes
     */
    public function warmupFrameworkClasses(): self
    {
        $frameworkClasses = [
            'App\Framework\Http\HttpRequest',
            'App\Framework\Http\HttpResponse',
            'App\Framework\Router\Route',
            'App\Framework\DI\Container',
            'App\Framework\Cache\Cache',
        ];

        foreach ($frameworkClasses as $className) {
            if (! empty($className) && ClassName::create($className)->exists()) {
                $this->cache->classCache->getClass(ClassName::create($className));
            }
        }

        return $this;
    }

    /**
     * Warm up cache with application-specific classes
     * @param array<string> $classNames
     */
    public function warmupApplicationClasses(array $classNames): self
    {
        foreach ($classNames as $className) {
            if (! empty($className) && ClassName::create($className)->exists()) {
                $this->cache->classCache->getClass(ClassName::create($className));
            }
        }

        return $this;
    }

    /**
     * Warm up cache for classes with specific attributes
     */
    public function warmupAttributeClasses(string $attributeClass): self
    {
        // This would require scanning all loaded classes
        // Implementation depends on specific requirements
        return $this;
    }
}
