<?php

namespace Licenzo\Framework\Support\Facades;

use Licenzo\Framework\Foundation\App;

class Facade
{
    /**
     * @throws \Exception
     */
    protected static function getFacadeAccessor()
    {
        throw new \Exception('Facade does not implement getFacadeAccessor method.');
    }

    /**
     * @throws \Exception
     */
    public static function __callStatic($method, $args)
    {
        $instance = static::resolveFacadeInstance(static::getFacadeAccessor());

        if (! $instance) {
            throw new \Exception('Facade instance not found.');
        }

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

    protected static function resolveFacadeInstance($name)
    {
        return App::getInstance()->make($name);
    }
}
