<?php

use Routes\RouteCollection as RouteCollection;
use ORM\Connections as Connections;
use Schema\Wrapper as Wrapper;
use App\Core\Template\Output as Output;

RouteCollection::get('*', function () {
    Output::addOnSubmenu('dev', '/paths', "Caminhos", "", ['class' => 'nav-link']);
}, -10)->doIgnore();

RouteCollection::cli('sanity/install', function() {
    Wrapper::set_driver(Connections::getConnection());
    Wrapper::begin();
    App\Core\Sanity\MigratorController::getInstance()->execute_plan();
    Wrapper::commit();

})->middlewareIgnore('auth');

RouteCollection::cli('install', function() {
    Wrapper::set_driver(Connections::getConnection());
    Wrapper::begin();
    App\Core\Sanity\MigratorController::getInstance()->execute_plan();
    Wrapper::commit();
})->middlewareIgnore('auth');

RouteCollection::cli('install/[d:module]', function() {
    Wrapper::set_driver(Connections::getConnection());
    Wrapper::begin();
    App\Core\Sanity\MigratorController::getInstance()->execute_plan();
    Wrapper::commit();
})->middlewareIgnore('auth');

RouteCollection::cli('reset', function() {
    Wrapper::set_driver(Connections::getConnection());
    Wrapper::begin();
    App\Core\Sanity\MigratorController::getInstance()->reset();
    Wrapper::commit();
});

RouteCollection::add('*', '*', function() {
    App\Core\Sanity\MigratorController::getInstance()->sentinel();
}, -19)->doIgnore()->middlewareIgnore('auth');
