<?php

/**
 * CometVisu Manager backend
 * PHP version 7.4
 *
 * @package OpenAPIServer
 * @author  OpenAPI Generator team
 * @link    https://github.com/openapitools/openapi-generator
 */

/**
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */

/**
 * NOTE: This class is auto generated by the openapi generator program.
 * https://github.com/openapitools/openapi-generator
 * Do not edit the class manually.
 */
namespace OpenAPIServer;

use Slim\Factory\AppFactory;
use Slim\Interfaces\RouteInterface;
use Slim\Exception\HttpNotImplementedException;
use Psr\Container\ContainerInterface;
use InvalidArgumentException;
use Dyorg\TokenAuthentication;
use Dyorg\TokenAuthentication\TokenSearch;
use Psr\Http\Message\ServerRequestInterface;
use OpenAPIServer\Mock\OpenApiDataMocker;
use OpenAPIServer\Mock\OpenApiDataMockerRouteMiddleware;
use Slim\Psr7\Factory\ResponseFactory;
use Exception;

/**
 * SlimRouter Class Doc Comment
 *
 * @package OpenAPIServer
 * @author  OpenAPI Generator team
 * @link    https://github.com/openapitools/openapi-generator
 */
class SlimRouter
{
    /** @var App instance */
    private $slimApp;

    /** @var array[] list of all api operations */
    private $operations = [
        [
            'httpMethod' => 'PUT',
            'basePathWithoutHost' => '',
            'path' => '/config/hidden',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractConfigApi',
            'userClassname' => 'ConfigApi',
            'operationId' => 'saveHiddenConfig',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Config option does not exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'POST',
            'basePathWithoutHost' => '',
            'path' => '/config/hidden/{section}/{key}',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractConfigApi',
            'userClassname' => 'ConfigApi',
            'operationId' => 'createHiddenConfig',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Config option does exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'DELETE',
            'basePathWithoutHost' => '',
            'path' => '/config/hidden/{section}/{key}',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractConfigApi',
            'userClassname' => 'ConfigApi',
            'operationId' => 'deleteHiddenConfig',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Config option does not exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/config/hidden/{section}/{key}',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractConfigApi',
            'userClassname' => 'ConfigApi',
            'operationId' => 'getHiddenConfig',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "oneOf" : [ {
          "$ref" : "#/components/schemas/HiddenConfig"
        }, {
          "$ref" : "#/components/schemas/ConfigSection"
        }, {
          "$ref" : "#/components/schemas/ConfigOptionValue"
        } ]
      }
    }
  }
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Config option does not exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'PUT',
            'basePathWithoutHost' => '',
            'path' => '/config/hidden/{section}/{key}',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractConfigApi',
            'userClassname' => 'ConfigApi',
            'operationId' => 'updateHiddenConfig',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Config option does not exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/addresses',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getAddresses',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/DataProviderResponse"
      }
    }
  }
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/designs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getDesigns',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "type" : "array",
        "items" : {
          "type" : "string"
        }
      }
    }
  }
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/influxdbfields',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getInfluxDBFields',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/DataProviderResponse"
      }
    }
  }
}',
                ],
                '406' => [
                    'jsonSchema' => '{
  "description" : "wrong measurement parameter"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/influxdbtags',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getInfluxDBTags',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/DataProviderResponse"
      }
    }
  }
}',
                ],
                '406' => [
                    'jsonSchema' => '{
  "description" : "wrong measurement parameter"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/influxdbs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getInfluxDBs',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/DataProviderResponse"
      }
    }
  }
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/data/rrds',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractDataproviderApi',
            'userClassname' => 'DataproviderApi',
            'operationId' => 'getRRDs',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/DataProviderResponse"
      }
    }
  }
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/fs/check',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'checkEnvironment',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/CheckResponse"
      }
    }
  }
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'POST',
            'basePathWithoutHost' => '',
            'path' => '/fs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'create',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '406' => [
                    'jsonSchema' => '{
  "description" : "File exists"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'DELETE',
            'basePathWithoutHost' => '',
            'path' => '/fs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'delete',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "File/Folder not found"
}',
                ],
                '406' => [
                    'jsonSchema' => '{
  "description" : "Folder not empty"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'PUT',
            'basePathWithoutHost' => '',
            'path' => '/fs/move',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'move',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Source does not exist"
}',
                ],
                '405' => [
                    'jsonSchema' => '{
  "description" : "Error occurred"
}',
                ],
                '406' => [
                    'jsonSchema' => '{
  "description" : "Target does exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/fs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'read',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/ReadResponse"
      }
    },
    "text/*" : {
      "schema" : {
        "type" : "string"
      }
    }
  }
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Path not found"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'PUT',
            'basePathWithoutHost' => '',
            'path' => '/fs',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractFsApi',
            'userClassname' => 'FsApi',
            'operationId' => 'update',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Not allowed"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "File does not exist"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'DELETE',
            'basePathWithoutHost' => '',
            'path' => '/proxy',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractRequestproxyApi',
            'userClassname' => 'RequestproxyApi',
            'operationId' => 'deleteProxied',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    },
    "image/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    }
  }
}',
                ],
                '401' => [
                    'jsonSchema' => '{
  "description" : "Unauthorized"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Forbidden"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Not found"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'GET',
            'basePathWithoutHost' => '',
            'path' => '/proxy',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractRequestproxyApi',
            'userClassname' => 'RequestproxyApi',
            'operationId' => 'getProxied',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    },
    "image/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    }
  }
}',
                ],
                '401' => [
                    'jsonSchema' => '{
  "description" : "Unauthorized"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Forbidden"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Not found"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'POST',
            'basePathWithoutHost' => '',
            'path' => '/proxy',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractRequestproxyApi',
            'userClassname' => 'RequestproxyApi',
            'operationId' => 'postProxied',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    },
    "image/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    }
  }
}',
                ],
                '401' => [
                    'jsonSchema' => '{
  "description" : "Unauthorized"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Forbidden"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Not found"
}',
                ],
            ],
            'authMethods' => [],
        ],
        [
            'httpMethod' => 'PUT',
            'basePathWithoutHost' => '',
            'path' => '/proxy',
            'apiPackage' => 'OpenAPIServer\Api',
            'classname' => 'AbstractRequestproxyApi',
            'userClassname' => 'RequestproxyApi',
            'operationId' => 'putProxied',
            'responses' => [
                '200' => [
                    'jsonSchema' => '{
  "description" : "successful operation",
  "content" : {
    "application/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    },
    "image/*" : {
      "schema" : {
        "type" : "string",
        "format" : "binary"
      }
    }
  }
}',
                ],
                '401' => [
                    'jsonSchema' => '{
  "description" : "Unauthorized"
}',
                ],
                '403' => [
                    'jsonSchema' => '{
  "description" : "Forbidden"
}',
                ],
                '404' => [
                    'jsonSchema' => '{
  "description" : "Not found"
}',
                ],
            ],
            'authMethods' => [],
        ],
    ];

    /**
     * Class constructor
     *
     * @param ContainerInterface|array $settings Either a ContainerInterface or an associative array of app settings
     *
     * @throws HttpNotImplementedException When implementation class doesn't exists
     * @throws Exception when not supported authorization schema type provided
     */
    public function __construct($settings = [])
    {
        if ($settings instanceof ContainerInterface) {
            // Set container to create App with on AppFactory
            AppFactory::setContainer($settings);
        }
        $this->slimApp = AppFactory::create();

        foreach ($this->operations as $operation) {
            $callback = function ($request, $response, $arguments) use ($operation) {
                $message = "How about extending {$operation['classname']} by {$operation['apiPackage']}\\{$operation['userClassname']} class implementing {$operation['operationId']} as a {$operation['httpMethod']} method?";
                throw new HttpNotImplementedException($request, $message);
            };
            $middlewares = [];

            if (class_exists("\\{$operation['apiPackage']}\\{$operation['userClassname']}")) {
                $callback = "\\{$operation['apiPackage']}\\{$operation['userClassname']}:{$operation['operationId']}";
            }

            $this->addRoute(
                [$operation['httpMethod']],
                "{$operation['basePathWithoutHost']}{$operation['path']}",
                $callback,
                $middlewares
            )->setName($operation['operationId']);
        }
    }

    /**
     * Merges user defined options with dynamic params
     *
     * @param array $staticOptions Required static options
     * @param array $userOptions   User options
     *
     * @return array Merged array
     */
    private function getTokenAuthenticationOptions(array $staticOptions, ?array $userOptions = null)
    {
        if (is_array($userOptions) === false) {
            return $staticOptions;
        }

        return array_merge($userOptions, $staticOptions);
    }

    /**
     * Returns app setting by name.
     *
     * @param ContainerInterface|array $settings    Either a ContainerInterface or an associative array of app settings
     * @param string                   $settingName Setting name
     * @param mixed                    $default     Default setting value.
     *
     * @return mixed
     */
    private function getSetting($settings, $settingName, $default = null)
    {
        if ($settings instanceof ContainerInterface && $settings->has($settingName)) {
            return $settings->get($settingName);
        } elseif (is_array($settings) && array_key_exists($settingName, $settings)) {
            return $settings[$settingName];
        }

        return $default;
    }

    /**
     * Add route with multiple methods
     *
     * @param string[]        $methods     Numeric array of HTTP method names
     * @param string          $pattern     The route URI pattern
     * @param callable|string $callable    The route callback routine
     * @param array|null      $middlewares List of middlewares
     *
     * @return RouteInterface
     *
     * @throws InvalidArgumentException If the route pattern isn't a string
     */
    public function addRoute(array $methods, string $pattern, $callable, $middlewares = [])
    {
        $route = $this->slimApp->map($methods, $pattern, $callable);
        foreach ($middlewares as $middleware) {
            $route->add($middleware);
        }
        return $route;
    }

    /**
     * Returns Slim Framework instance
     *
     * @return App
     */
    public function getSlimApp()
    {
        return $this->slimApp;
    }
}
