<?php

namespace ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS;

class RequestFactory
{
    public static $RequestRoutes = [
        'fastdomainlookup' => 'Fastlookup\FastDomainLookup'
    ];

    public static function build($func, $type, $dataObject)
    {
        $route              = '';
        $routeKey           = strtolower($func);
        $returnFullResponse = true;

        if (array_key_exists($routeKey, self::$RequestRoutes))
        {
            $route = self::$RequestRoutes[$routeKey];
        }

        $class = '\ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS\\' . $route;

        if (class_exists($class))
        {
            /* if (!isset($dataObject->attributes)) {
              $dataconversionRoute = '\ModulesGarden\ProxmoxAddon\App\Api\OpenSRS\backwardcompatibility\dataconversion\\'.$route;

              if (class_exists($dataconversionRoute)) {
              $dc = new $dataconversionRoute();

              $dataObject = $dc->convertDataObject($dataObject);

              $returnFullResponse = false;
              }
              } */

            return new $class($type, $dataObject, $returnFullResponse);
        }
        else
        {
            throw new \Exception("OSRS Error - $func is unsupported.");
        }
    }
}
