<?php

declare(strict_types=1);

namespace App\Framework\View\Exception;

use App\Framework\Exception\ErrorCode;
use App\Framework\Exception\ExceptionContext;
use App\Framework\Exception\FrameworkException;

/**
 * Legacy Template Exception - wird zu TemplateNotFoundException migriert
 * @deprecated Use TemplateNotFoundException instead
 */
final class TemplateNotFound extends FrameworkException
{
    public static function forTemplate(string $template, ?string $searchPath = null, ?\Throwable $previous = null): self
    {
        $context = ExceptionContext::forOperation('template_loading', 'TemplateLoader')
            ->withData([
                'template' => $template,
                'search_path' => $searchPath,
                'timestamp' => microtime(true),
            ]);

        return self::fromContext(
            "Das Template '$template' konnte nicht geladen werden.",
            $context,
            ErrorCode::TPL_TEMPLATE_NOT_FOUND,
            $previous
        );
    }

    /**
     * Legacy constructor für Backward Compatibility
     * @deprecated Use forTemplate() factory method instead
     */
    public function __construct(string $template, ?\Throwable $previous = null, int $code = 0, array $context = [])
    {
        $exceptionContext = ExceptionContext::forOperation('template_loading', 'TemplateLoader')
            ->withData(['template' => $template] + $context);

        parent::__construct(
            message: "Das Template '$template' konnte nicht geladen werden.",
            context: $exceptionContext,
            errorCode: ErrorCode::TPL_TEMPLATE_NOT_FOUND,
            previous: $previous
        );
    }
}
