#!/usr/bin/env php
<?php

/**
 * This file is part of the haphan/php-rage4-dns-api Library.
 *
 * (c) Ha Phan <thanhha.work@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

error_reporting(E_ALL);
ini_set('display_errors', 'true');

//CURL extension must installed to run this console
if (!extension_loaded('curl') || !function_exists('curl_init')) {
    die(<<<EOT
cURL has to be enabled!
EOT
    );
}


function includeIfExists($file)
{
    if (file_exists($file)) {
        return include $file;
    }
}

//Bootstrap application with autoload
if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) &&
    (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) {
    die(<<<EOT
You must set up the project dependencies, run the following commands:
$ wget http://getcomposer.org/composer.phar
OR
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install --dev
EOT
    );
}

use Symfony\Component\Console\Application as BaseApplication;
use Haphan\Rage4DNS\Command;

class Application extends BaseApplication{

    private $logo = <<<LOGO

  ____                  _  _     ____  _   _ ____
 |  _ \ __ _  __ _  ___| || |   |  _ \| \ | / ___|
 | |_) / _` |/ _` |/ _ \ || |_  | | | |  \| \___ \
 |  _ < (_| | (_| |  __/__   _| | |_| | |\  |___) |
 |_| \_\__,_|\__, |\___|  |_|   |____/|_| \_|____/
             |___/

LOGO;

    public function getHelp()
    {
        return $this->logo . parent::getHelp();
    }
}

$console = new Application();
$console->getHelp();
$console->setName('Rage4DNS :: Console Tool and PHP 5.3+ Library');
$console->setVersion('1.0');

//Domain related commands
$console->add(new Command\Domains\GetAllCommand());
$console->add(new Command\Domains\GetByIDCommand());
$console->add(new Command\Domains\GetByNameCommand());
$console->add(new Command\Domains\CreateDomainCommand());
$console->add(new Command\Domains\CreateDomainVanityCommand());
$console->add(new Command\Domains\DeleteDomainCommand());
$console->add(new Command\Domains\UpdateDomainCommand());
$console->add(new Command\Domains\ExportCommand());

//Usage related commands
$console->add(new Command\Usage\GlobalUsageCommand());
$console->add(new Command\Usage\DomainUsageCommand());

//Records related commands
$console->add(new Command\Records\GetTypesCommand());
$console->add(new Command\Records\GetRegionsCommand());
$console->add(new Command\Records\GetRecordsCommand());
$console->add(new Command\Records\CreateRecordCommand());
$console->add(new Command\Records\DeleteRecordCommand());
$console->add(new Command\Records\UpdateRecordCommand());

//Run console
$console->run();

