<?php
/**
 * @package   Gridbox
 * @author    Balbooa https://www.balbooa.com/
 * @copyright Copyright © Balbooa
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace Balbooa\Component\Forms\Site\Helper\Uploads\Factory;

use Balbooa\Component\Forms\Site\Helper\Uploads\Contracts\UploadsInterface;
use Balbooa\Component\Forms\Site\Helper\Uploads\Enums\UploadEnum;

defined('_JEXEC') or die;

class UploadsFactory
{
    protected static array $instances = [];

    public static function getInstance(UploadEnum $type): UploadsInterface
    {
        $key = $type->value;
        if (isset(self::$instances[$key])) {
            return self::$instances[$key];
        }

        $className = $type->getClass();

        if (!class_exists($className)) {
            throw new \RuntimeException("Class $className not found");
        }

        $instance = new $className();
        self::$instances[$key] = $instance;

        return $instance;
    }
}