<?php

namespace App\Console\Commands\Utility;

use App\Helpers\Api\PhpCreatia;

class TestPhpCreatia extends \App\Console\Commands\BaseCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test:php-creatia';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Tests PHP Creatia. This requires custom testing methodology since it is fundamentally an API based call.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

        // This key is safe in the codebase, it doesn't matter - It only works on the devbox and only works from the devbox.
        $api = new PhpCreatia('https://spicy-creatia.securelayer.com', "6rlozS79M7u2IJViPKrKxP9IPayhIOGL", "kTZrsWYh3qGRUAisWxw2mtLVRdEDt5F3");

        $call_1 = $api->createOrganisation('Organisation A', [[ 'key' => 'gsl-whmcs', 'identity' => '1121' ]], 'gsl');
        $call_2 = $api->createOrganisation('Organisation B', [[ 'key' => 'gd-whmcs', 'identity' => '2221' ]], 'go-dedicated');
        $call_3 = $api->createOrganisation('Organisation C', [[ 'key' => 'sl-whmcs', 'identity' => '3321' ]], 'streamline');

        echo json_encode($call_1) . "\n";
        echo json_encode($call_2) . "\n";
        echo json_encode($call_3) . "\n";

        $call_4 = $api->getExternalIdentities('gsl-whmcs');
        $call_5 = $api->getExternalIdentities('gd-whmcs', '2221');

        echo json_encode($call_4) . "\n";
        echo json_encode($call_5) . "\n";

        $call_6 = $api->associateSubnet($call_5['data'][0]['creatia_id'], '103.1.213.13/32', 'Devbox Test', true, true, false, 'gsl');

        echo json_encode($call_6) . "\n";

        $call_7 = $api->setSubnetMitigation($call_6['detail'], true, false, false, 3);

        echo json_encode($call_7) . "\n";

        return 0;
    }
}