<?php
declare(strict_types=1);

namespace App\Core;

abstract class Facade
{
    abstract protected static function getContainerKey(): string;

    public static function __callStatic(string $method, array $args): mixed
    {
        $instance = App::getInstance()->resolve(static::getContainerKey());

        if ($instance === null) {
            throw new \RuntimeException('Service not bound in container: ' . static::getContainerKey());
        }

        return $instance->$method(...$args);
    }

    public static function instance(): object
    {
        $instance = App::getInstance()->resolve(static::getContainerKey());

        if ($instance === null) {
            throw new \RuntimeException('Service not bound in container: ' . static::getContainerKey());
        }

        return $instance;
    }
}
