<?php

// Functions and constants

namespace {

}


namespace FluxAIMediaAltCreator {

    class AliasAutoloader
    {
        private string $includeFilePath;

        private array $autoloadAliases = array (
  'FluxPlugins\\Common\\Account\\AccountIdService' => 
  array (
    'type' => 'class',
    'classname' => 'AccountIdService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Account',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Account\\AccountIdService',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Api\\ExternalApiClient' => 
  array (
    'type' => 'class',
    'classname' => 'ExternalApiClient',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Api',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Api\\ExternalApiClient',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Compatibility\\CompatibilityNoticeHandler' => 
  array (
    'type' => 'class',
    'classname' => 'CompatibilityNoticeHandler',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Compatibility',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Compatibility\\CompatibilityNoticeHandler',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Compatibility\\CompatibilityResponse' => 
  array (
    'type' => 'class',
    'classname' => 'CompatibilityResponse',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Compatibility',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Compatibility\\CompatibilityResponse',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Compatibility\\CompatibilityResponseItem' => 
  array (
    'type' => 'class',
    'classname' => 'CompatibilityResponseItem',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Compatibility',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Compatibility\\CompatibilityResponseItem',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Compatibility\\CompatibilityValidator' => 
  array (
    'type' => 'class',
    'classname' => 'CompatibilityValidator',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Compatibility',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Compatibility\\CompatibilityValidator',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\FluxPlugins' => 
  array (
    'type' => 'class',
    'classname' => 'FluxPlugins',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\FluxPlugins',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Http\\Controllers\\LicenseController' => 
  array (
    'type' => 'class',
    'classname' => 'LicenseController',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Http\\Controllers',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Http\\Controllers\\LicenseController',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Http\\Controllers\\LogsController' => 
  array (
    'type' => 'class',
    'classname' => 'LogsController',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Http\\Controllers',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Http\\Controllers\\LogsController',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\License\\LicenseService' => 
  array (
    'type' => 'class',
    'classname' => 'LicenseService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\License',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\License\\LicenseService',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Logger\\DatabaseHandler' => 
  array (
    'type' => 'class',
    'classname' => 'DatabaseHandler',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Logger',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Logger\\DatabaseHandler',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Logger\\Logger' => 
  array (
    'type' => 'class',
    'classname' => 'Logger',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Logger',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Logger\\Logger',
    'implements' => 
    array (
      0 => 'Psr\\Log\\LoggerInterface',
    ),
  ),
  'FluxPlugins\\Common\\Services\\CompatibilityService' => 
  array (
    'type' => 'class',
    'classname' => 'CompatibilityService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Services',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Services\\CompatibilityService',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Services\\I18n' => 
  array (
    'type' => 'class',
    'classname' => 'I18n',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Services',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Services\\I18n',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Services\\LogsService' => 
  array (
    'type' => 'class',
    'classname' => 'LogsService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Services',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Services\\LogsService',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Services\\MenuService' => 
  array (
    'type' => 'class',
    'classname' => 'MenuService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Services',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Services\\MenuService',
    'implements' => 
    array (
    ),
  ),
  'FluxPlugins\\Common\\Services\\RestApiService' => 
  array (
    'type' => 'class',
    'classname' => 'RestApiService',
    'isabstract' => false,
    'namespace' => 'FluxPlugins\\Common\\Services',
    'extends' => 'FluxAIMediaAltCreator\\FluxPlugins\\Common\\Services\\RestApiService',
    'implements' => 
    array (
    ),
  ),
);

        public function __construct()
        {
            $this->includeFilePath = __DIR__ . '/autoload_alias.php';
        }

        public function autoload($class)
        {
            if (!isset($this->autoloadAliases[$class])) {
                return;
            }
            switch ($this->autoloadAliases[$class]['type']) {
                case 'class':
                        $this->load(
                            $this->classTemplate(
                                $this->autoloadAliases[$class]
                            )
                        );
                    break;
                case 'interface':
                    $this->load(
                        $this->interfaceTemplate(
                            $this->autoloadAliases[$class]
                        )
                    );
                    break;
                case 'trait':
                    $this->load(
                        $this->traitTemplate(
                            $this->autoloadAliases[$class]
                        )
                    );
                    break;
                default:
                    // Never.
                    break;
            }
        }

        private function load(string $includeFile)
        {
            file_put_contents($this->includeFilePath, $includeFile);
            include $this->includeFilePath;
            file_exists($this->includeFilePath) && unlink($this->includeFilePath);
        }

        private function classTemplate(array $class): string
        {
            $abstract = $class['isabstract'] ? 'abstract ' : '';
            $classname = $class['classname'];
            if (isset($class['namespace'])) {
                $namespace = "namespace {$class['namespace']};";
                $extends = '\\' . $class['extends'];
                $implements = empty($class['implements']) ? ''
                : ' implements \\' . implode(', \\', $class['implements']);
            } else {
                $namespace = '';
                $extends = $class['extends'];
                $implements = !empty($class['implements']) ? ''
                : ' implements ' . implode(', ', $class['implements']);
            }
            return <<<EOD
                <?php
                $namespace
                $abstract class $classname extends $extends $implements {}
                EOD;
        }

        private function interfaceTemplate(array $interface): string
        {
            $interfacename = $interface['interfacename'];
            $namespace = isset($interface['namespace'])
            ? "namespace {$interface['namespace']};" : '';
            $extends = isset($interface['namespace'])
            ? '\\' . implode('\\ ,', $interface['extends'])
            : implode(', ', $interface['extends']);
            return <<<EOD
                <?php
                $namespace
                interface $interfacename extends $extends {}
                EOD;
        }
        private function traitTemplate(array $trait): string
        {
            $traitname = $trait['traitname'];
            $namespace = isset($trait['namespace'])
            ? "namespace {$trait['namespace']};" : '';
            $uses = isset($trait['namespace'])
            ? '\\' . implode(';' . PHP_EOL . '    use \\', $trait['use'])
            : implode(';' . PHP_EOL . '    use ', $trait['use']);
            return <<<EOD
                <?php
                $namespace
                trait $traitname { 
                    use $uses; 
                }
                EOD;
        }
    }

    spl_autoload_register([ new AliasAutoloader(), 'autoload' ]);
}
