<?php

// Laravel Specifics
use Illuminate\Support\Facades\Auth;

// De-authenticate users that have been deleted. Exists as a safeguard more than anything. Move this out.
$user = Auth::user();

if($user) {
    if($user->deleted_at !== null) {
        Auth::logout();    
    }
}

/*
 * Load up routes, we structure things this way to keep everything pretty readable, but also to only ensure things are registered when it is intended.
 * 
 * Previous versions of Creatia had the issue of massive route files, which made things far harder to maintain. 
 */
$routes = [
    'api' => [
        'authentication' => [
            'Account',
            'Token'
        ],
        'billing'   => config('app.enterprise') ? [] : [
            'Billing'
        ],
        'standard' => [
            'AccessToken',
            'Organisation',
            ...(config('app.enterprise') ? [] : ['OrganisationApi']),
            'Hooks',
            ...(config('app.enterprise') ? [] : ['Whmcs'])
        ],
        'goliath' => [
            'GoliathAgent',
            'GoliathLevel1',
            'GoliathLevel2',
            'GoliathReport'
        ],
        'mercury' => config('app.enterprise') ? [] : [
            'MercuryV2'
        ],
        'mitigation' => [
            'MitigationAttack'
        ],
        'misc' => config('app.enterprise') ? [] : [
            'Misc'
        ],
        'network' => [
            'Network',
            ...(config('app.enterprise') ? [] : ['NetworkApi'])
        ],
        'locus' => config('app.enterprise') ? [] : [
            'Locus'
        ],
        'provisioning' => config('app.enterprise') ? [] : [
            'Provisioning'
        ]
    ]
];

foreach ($routes as $i_folder => $i_routes) {
    foreach($i_routes as $j_folder => $j_routes) {
        foreach($j_routes as $j_route) {
            include_once __DIR__ . "/$i_folder/$j_folder/$j_route.php";

            $j_route::routes();
        }
    }
}