<?php

use App\Http\Controllers\AccountController;
use App\Http\Controllers\AdvancedSearch;
use App\Http\Controllers\Auth\BlockedController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\OnboardingController;
use App\Http\Controllers\PaymentsController;
use App\Http\Controllers\PayRefController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\ServiceGroupController;
use App\Http\Controllers\SubAccountController;
use App\Http\Controllers\SubContractController;
use App\Http\Controllers\TokensController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ClientController;
use App\Http\Controllers\ContractController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return redirect()->route('login');
});

Route::get('/notification', function () {
    $user = \App\Models\User::find(1);

    return (new \App\Notifications\AccountDeactivated($user))
        ->toMail($user);
});

Auth::routes();

//check for authenticated users
Route::middleware(['auth', 'check.user_status'])->group(function () {
    Route::middleware('check.contract_status')->group(function () {
        //@TODO change this route to limit http req
        Route::name('basic.')->group(function () {
            Route::resource('meta/search', SearchController::class)->only([
                'index', 'show', 'store'
            ]);
        });
        Route::name('advance.')->group(function () {
            Route::resource('meta/adv/search', AdvancedSearch::class)->only([
                'index', 'show', 'store'
            ]);
        });
    });

    // client sub-account (users)
    Route::resource('sub-account', SubAccountController::class);

    // client sub-account (contracts)
    Route::resource('sub-contracts', SubContractController::class);

    // my account profile
    Route::resource('account', AccountController::class);

    //role access (Admin and super)
    Route::group(['middleware' => ['role:super admin|admin|manager']], function () {
        Route::prefix('admin')->group(function () {
            Route::resource('client/onboarding', OnboardingController::class);
            //contracts and clients
            Route::resource('client', ClientController::class);
            Route::resource('contract', ContractController::class);
            //user
            Route::resource('user', UserController::class);
            //roles and permission
            Route::resource('role', RoleController::class);
            Route::put('role/{role_id}/add-permissions', [RoleController::class, 'addPermissionToRole'])
                ->name('add_permission_to_role');
            Route::resource('permission', PermissionController::class);
            //services
            Route::resource('service', ServiceController::class);
            //service group
            Route::resource('service-group', ServiceGroupController::class);
            //payments
            Route::resource('payments', PaymentsController::class);
            //Tokens
            Route::resource('tokens', TokensController::class);
        });
    }); //End admin

});//end Auth

// get app notifications
Route::get('notifications/get', [NotificationController::class, 'get'])->name("notifications.get");
Route::get('notifications/all', [NotificationController::class, 'all'])->name("notifications.all");

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::get('/dashboard', [App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard');

Route::get('/blocked', BlockedController::class)->name('blocked');


