<?php

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\{HomeController,
	DomainController,
	EchoareaController,
	EchomailController,
	FileareaController,
	NetmailController,
	SystemController,
	UserController,
	UserSwitchController,
	ZoneController};
use App\Http\Controllers\Auth\LoginController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Auth::routes([
	'login'         => true,
	'logout'        => true,
	'register'      => true,
	'reset'         => true,       // for resetting passwords
	'confirm'       => true,       // for additional password confirmations
	'verify'        => true,       // for email verification
]);
Route::get('logout',[LoginController::class,'logout']);
Route::get('admin/switch/start/{o}',[UserSwitchController::class,'user_switch_start']);
Route::get('admin/switch/stop',[UserSwitchController::class,'user_switch_stop']);

// Unauthed routes
Route::get('/',[HomeController::class,'home']);
Route::view('about','about');
Route::view('domain/list','domain.list');
Route::get('network/{o}',[HomeController::class,'network'])
	->where('o','[0-9]+');
Route::match(['get','post'],'pkt',[HomeController::class,'pkt']);
Route::view('system/list','system.list');
Route::get('system/view/{o}',[SystemController::class,'view'])
	->where('o','[0-9]+');
Route::get('search',[HomeController::class,'search']);

Route::middleware(['auth','verified','activeuser'])->group(function () {
	Route::get('addresses/orphan',[SystemController::class,'api_orphan_address']);
	Route::get('dashboard',[UserController::class,'dashboard']);
	Route::post('default/{o}',[ZoneController::class,'api_default'])
		->where('o','[0-9]+');

	Route::get('ftn/domain',[DomainController::class,'home']);
	Route::match(['get','post'],'ftn/domain/addedit/{o?}',[DomainController::class,'add_edit'])
		->where('o','[0-9]+');
	Route::get('ftn/echoarea',[EchoareaController::class,'home']);
	Route::match(['get','post'],'ftn/echoarea/addedit/{o?}',[EchoareaController::class,'add_edit'])
		->where('o','[0-9]+');
	Route::get('ftn/filearea',[FileareaController::class,'home']);
	Route::match(['get','post'],'ftn/filearea/addedit/{o?}',[FileareaController::class,'add_edit'])
		->where('o','[0-9]+');

	Route::get('ftn/our_systems',[SystemController::class,'ours']);

	Route::get('ftn/system',[SystemController::class,'home']);
	Route::match(['get','post'],'ftn/system/addedit/{o?}',[SystemController::class,'add_edit'])
		->where('o','[0-9]+');
	Route::post('ftn/system/addaddress/{o}',[SystemController::class,'add_address'])
		->where('o','[0-9]+');
	Route::post('ftn/system/addsession/{o}',[SystemController::class,'add_session'])
		->where('o','[0-9]+');
	Route::get('ftn/system/deladdress/{o}',[SystemController::class,'del_address'])
		->where('o','[0-9]+');
	Route::get('ftn/system/demaddress/{o}',[SystemController::class,'dem_address'])
		->where('o','[0-9]+');
	Route::get('ftn/system/delsession/{o}/{zo}',[SystemController::class,'del_session'])
		->where('o','[0-9]+')
		->where('zo','[0-9]+');
	Route::get('ftn/system/proaddress/{o}',[SystemController::class,'pro_address'])
		->where('o','[0-9]+');
	Route::match(['get','post'],'ftn/system/echoarea/{o}',[SystemController::class,'echoareas'])
		->where('o','[0-9]+');
	Route::match(['get','post'],'ftn/system/filearea/{o}',[SystemController::class,'fileareas'])
		->where('o','[0-9]+');
	Route::match(['get','post'],'ftn/system/movaddress/{so}/{o}',[SystemController::class,'mov_address'])
		->where('so','[0-9]+')
		->where('o','[0-9]+');
	Route::post('file/contents/{o}/{date}',[HomeController::class,'file_contents'])
		->where('o','[0-9]+')
		->where('date','[0-9:\-@]+');
	Route::get('ftn/system/recaddress/{id}',[SystemController::class,'rec_address'])
		->where('o','[0-9]+');
	Route::get('ftn/system/puraddress/{id}',[SystemController::class,'pur_address'])
		->where('o','[0-9]+');
	Route::get('ftn/system/susaddress/{o}',[SystemController::class,'sus_address'])
		->where('o','[0-9]+');
	Route::get('ftn/zone',[ZoneController::class,'home']);
	Route::match(['get','post'],'ftn/zone/addedit/{o?}',[ZoneController::class,'add_edit'])
		->where('o','[0-9]+');

	Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts'])
		->where('o','[0-9]+');
	Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs'])
		->where('o','[0-9]+');
	Route::match(['get','post'],'link',[UserController::class,'link']);
	Route::post('packet/contents/{o}/{packet}',[HomeController::class,'packet_contents'])
		->where('o','[0-9]+')
		->where('packet','[0-9a-f]+');
	Route::get('permissions',[HomeController::class,'permissions']);
	Route::get('regions/{o}',[DomainController::class,'api_regions'])
		->where('o','[0-9]+');
	Route::post('system/address/{o}',[SystemController::class,'api_address'])
		->where('o','[0-9]+');
	Route::get('systems/orphan',[SystemController::class,'api_orphan']);
	Route::match(['get','post'],'user/system/register',[SystemController::class,'system_register']);
	Route::match(['post'],'user/system/link',[SystemController::class,'system_link']);
});

Route::middleware(['auth','can:admin'])->group(function () {
	Route::get('echomail/view/{o}',[EchomailController::class,'view']);
	Route::get('netmail/view/{o}',[NetmailController::class,'view']);
	Route::get('user/list',[UserController::class,'home']);
	Route::match(['get','post'],'setup',[HomeController::class,'setup']);
	Route::match(['get','post'],'user/addedit/{o?}',[UserController::class,'add_edit'])
		->where('o','[0-9]+');
});