<?php

declare(strict_types=1);

namespace App\Framework\DI\Exceptions;

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

/**
 * Exception thrown when DefaultImplementation attribute validation fails
 */
final class DefaultImplementationException extends RuntimeException
{
    /**
     * Thrown when a class with DefaultImplementation attribute does not implement the specified interface
     *
     * @param class-string $className
     * @param class-string $interface
     */
    public static function doesNotImplementInterface(string $className, string $interface): self
    {
        return new self(
            sprintf(
                'Class "%s" has #[DefaultImplementation] for interface "%s" but does not implement that interface',
                $className,
                $interface
            )
        );
    }

    /**
     * Thrown when a class with DefaultImplementation attribute (without explicit interface) implements no interfaces
     *
     * @param class-string $className
     */
    public static function noInterfacesImplemented(string $className): self
    {
        return new self(
            sprintf(
                'Class "%s" has #[DefaultImplementation] without explicit interface but implements no interfaces. ' .
                'Either specify an interface explicitly or ensure the class implements at least one interface.',
                $className
            )
        );
    }

    /**
     * Thrown when the specified interface does not exist
     *
     * @param class-string $className
     * @param string $interface
     */
    public static function interfaceDoesNotExist(string $className, string $interface): self
    {
        return new self(
            sprintf(
                'Class "%s" has #[DefaultImplementation] for interface "%s" which does not exist',
                $className,
                $interface
            )
        );
    }
}
