<?php

use NovakSolutions\FrontDesk\Generate;
use Doctrine\Common\Inflector;
require_once '/vendor/autoload.php';
$coreParser = new Generate\CoreParser();
$coreApiDocsAsHtml = http_get_contents("https://developer.frontdeskhq.com/docs/api/v2");
$definitions = $coreParser->extractDataFromHtml($coreApiDocsAsHtml);
$modelDefinitions = $coreParser->convertToModels($definitions);
//Process Definitions Info Select, Update, Insert, etc...
/** @var mixed $models */
$template = getTwigTemplate();
$models = array();
/**
 * @param $selectMethod
 * @return string
 */
$baseClass = 'CoreModel';
foreach ($modelDefinitions as $place => $models) {
    foreach ($models as $modelName => $model) {
        $standardMethods = array();
        $fields = $model['fields'];
        $renderedTemplate = $template->render(compact('model', 'baseClass'));
        if (!file_exists("src/Model/{$place}")) {
            mkdir("src/Model/{$place}");
        }
        file_put_contents("src/Model/{$place}/" . $modelName . '.php', $renderedTemplate);
    }
}
function http_get_contents($url)
{
<?php

use NovakSolutions\FrontDesk\Generate;
use Doctrine\Common\Inflector;
require_once '/vendor/autoload.php';
$coreParser = new Generate\CoreParser();
$coreApiDocsAsHtml = http_get_contents("https://developer.frontdeskhq.com/docs/api/v2");
$coreDefinitions = $coreParser->extractDataFromHtml($coreApiDocsAsHtml);
//Process Definitions Info Select, Update, Insert, etc...
/** @var mixed $models */
$models = array();
$loader = new Twig_Loader_Filesystem('src/Generate/Templates');
$twig = new Twig_Environment($loader);
$twig->addExtension(new Twig_Extension_Debug());
$twig->setCache(false);
$function = new Twig_SimpleFunction('descriptionToPhpDocType', function ($type) {
    switch ($type) {
        case 'boolean':
            return "boolean";
        default:
            return $type;
    }
});
$twig->addFunction($function);
$rpad10Filter = new Twig_SimpleFilter("rpad10", function ($string) {
    return str_pad($string, 10, " ", STR_PAD_RIGHT);
});
$rpad20Filter = new Twig_SimpleFilter("rpad20", function ($string) {
    return str_pad($string, 20, " ", STR_PAD_RIGHT);
});
$twig->addFilter($rpad10Filter);