<?php

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Mail;


use App\Http\Controllers\Auth\ResetPasswordController;
use App\Http\Controllers\Auth\RegisteredUserController;

use App\Http\Controllers\Auth\PasswordResetLinkController;
use Illuminate\Foundation\Auth\EmailVerificationRequest;


use App\Http\Controllers\CustomRegistrationController;
use App\Http\Controllers\CreateProjectController;

use App\Http\Controllers\ForgotPasswordController;
use App\Http\Controllers\FormController;

use App\Http\Controllers\NewPasswordController;
use App\Http\Controllers\userController;

use App\Http\Controllers\Pending_UserController;
use App\Http\Controllers\ProjectoDatacontroller;

use App\Http\Controllers\PreparedProjectController;
use App\Http\Controllers\ExecutionProjectController;
use App\Http\Controllers\WorkstationsJobsController;


// Esta rota so pode aceder quem tiver o link atravez do email 
Route::get('formulario', function () {
    return view('email/FormAdmin');
})->name('formulario');

// Email
Route::get('/your-verification-route/{id}/{hash}', [UserController::class, 'yourVerificationMethod'])
    ->middleware(['auth', 'signed', 'throttle:6,1'])
    ->name('verification.verify');


/*
|--------------------------------------------------------------------------
| 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!
|
*/

// Rotas protegidas que exigem verificação de e-mail
Route::middleware(['auth'])->group(function () {

    /*
    |--------------------------------------------------------------------------
    | User_Type (tecnico)
    |--------------------------------------------------------------------------
    |*** Routes unique access to the technical 
    */
    Route::middleware(['checkUserType:enterWorkstation'])->group(function () {
        
        Route::get('enterWorkstation', function () {
            return view('workstations.start');
        })->name('enterWorkstation');
        
        Route::get('/getEquipmentData/{equipment_id}', [WorkstationsJobsController::class, 'getEquipmentData'])->name('getEquipmentData');
        Route::post('receiveAnswersEquipment', [WorkstationsJobsController::class, 'receiveAnswersEquipment'])->name('receiveAnswersEquipment');
    });

     /*
    |--------------------------------------------------------------------------
    | User_Type (Super_Administrador)
    |--------------------------------------------------------------------------
    |*** Routes unique access to the Super_Administrator, Administrator 
    */
    Route::middleware(['checkUserType:home'])->group(function () {
        Route::get('/', [ProjectoDatacontroller::class, ('HomePage')])->name('home');

        /*
        |--------------------------------------------------------------------------
        | CRUD - users
        |--------------------------------------------------------------------------
        | Definition routes to implement the CRUD model
        */
        Route::controller(userController::class)
            ->group(function () {

                Route::get('users/listUsers', 'listUsers')->name('users.list');
                Route::get('users/listCompanies', 'listCompanies')->name('users.company');
                Route::get('users/{id}', 'show')->name('users.Show');
                Route::get('users/{id}/edit', 'edit')->name('users.edit');
                Route::put('users/{user}', 'update')->name('users.update');
                Route::delete('users/{user}', 'destroy')->name('users.destroy');
                Route::post('editProfile/{id}', 'EditProfile')->name('editProfile');
            });

            /*
        |--------------------------------------------------------------------------
        | Management of projects created
        |--------------------------------------------------------------------------
        | 
        */
        Route::controller(CreateProjectController::class)
            ->group(function () {

                // indication of progress bar to projects that are in 'Planning'
                Route::get('test1/{id}', 'showStep1')->name('test1');
                Route::get('test2/{id}', 'showStep2')->name('test2');
                Route::get('test3/{id}', 'showStep3')->name('test3');

                // Para adicionar uma tarefa Complementar
                Route::post('addFurtherTasks', 'addFurtherTasks')->name('addFurtherTasks');
                Route::post('deleteFurtherTasks', 'deleteFurtherTasks')->name('deleteFurtherTasks');

                Route::get('createProject', 'createProjectForStep1')->name('createProject');

                Route::post('receiveEquipmentToAssociateTasks', 'receiveEquipmentToAssociateTasks')->name('receiveEquipmentToAssociateTasks');
                Route::get('finishCreatingProject/{numberProject}', 'finishCreatingProject')->name('finishCreatingProject');
                Route::get('testDataTables', 'testDataTables')->name('testDataTables');
                Route::get('workstationsAssociationTasks', 'workstationsAssociationTasks')->name('workstationsAssociationTasks');
                Route::get('AddNomenclatureWorkstation', 'AddNomenclatureWorkstation')->name('AddNomenclatureWorkstation');
                Route::get('removeProjectEquipment', 'removeProjectEquipment')->name('removeProjectEquipment');
                Route::delete('deleteWorkstation/{name}', 'deleteWorkstation')->name('deleteWorkstation');
                Route::post('EditEquipmentsProjects', 'EditEquipmentsProjects')->name('EditEquipmentsProjects');
                Route::post('newProject1', 'processStep1')->name('processStep1');
                Route::post('createWorkStations', 'createWorkStations')->name('createWorkStations');

                Route::post('test1', 'EditprocessStep1')->name('EditprocessStep1');
                Route::post('test2', 'processStep2')->name('processStep2');
                Route::post('test2CreateEquipment', 'createEquipmentManual')->name('test2CreateEquipment');
                Route::post('test3', 'processStep3');
                Route::delete('removeEquipment/{id}', 'removePendingEquipment')->name('removeEquipment');
                Route::post('CreateNewEquipmentFromPendingEquipment/{id}', 'CreateNewEquipmentFromPendingEquipment')->name('CreateNewEquipmentFromPendingEquipment');
                Route::post('create-equipament-project', 'createEquipamentProject')->name('createEquipamentProject');
                Route::get('equipments/{id}/attributes', 'getAttributes');

                /*
                |--------------------------------------------------------------------------
                | Template Excel
                |--------------------------------------------------------------------------
                */
                Route::get('template1/{numberProject}', 'receiveUnitsForExcelTemplate')->name('download');
            });

        Route::get('user-data', [PreparedProjectController::class, 'getData1'])->name('getData');
        Route::get('preparedProject/{ProjectId}', [PreparedProjectController::class, 'PreparedProject'])->name('preparedProject');
        Route::get('EditProjectForArticulated', [PreparedProjectController::class, 'editProjectForArticulated'])->name('EditProjectForArticulated');

        Route::get('ExecutionProject/{ProjectId}', [ExecutionProjectController::class, 'receiveExecutionProject'])->name('ExecutionProject');
        Route::get('/ReceiveEquipmentIdForShowModal/{EquipmentID}', [ExecutionProjectController::class, 'receiveEquipmentIdForShowModal'])->name('ReceiveEquipmentIdForShowModal ');


        //Gerir os Ativos gerais
        Route::get('manageAssets', [ProjectoDatacontroller::class, 'ManageAssets'])->name('manageAssets');
        Route::get('units/{id}', [ProjectoDatacontroller::class, 'showUnit'])->name('showUnit');


        Route::get('usersProfiles/{id}', [userController::class, 'UserProfile'])->name('usersProfiles');
        Route::post('enviar-formulario', [FormController::class, 'enviarEmail'])->name('enviar.formulario');

        Route::get('/CreateUsers/{id}', [Pending_UserController::class, 'ShowFormUser'])->name('ShowPendingUser');
        Route::post('formulario/receive', [Pending_UserController::class, 'store'])->name('criarUser');
        Route::get('/CreateUsers', [Pending_UserController::class, 'ListPendingUsers'])->name('CreateUsers');
        Route::post('/register', [CustomRegistrationController::class, 'store'])->name('register');

        //  Mostrar Instalação click

        // Route::middleware(['checkUserType:enterWorkstation'])
    });
});

// *** All api routes have been moved to api.php ***
Route::get('/api/receiveEquipmentsExecutionProject/{receiveNumberProject}', [ExecutionProjectController::class, 'receiveEquipmentsExecutionProject'])->name('receiveEquipmentsExecutionProject');
Route::get('/api/receiveAllEquipments', [ProjectoDatacontroller::class, 'receiveAllEquipments']);
Route::get('/api/receiveEquipmentsProject/{receiveNumberProject}', [ProjectoDatacontroller::class, 'receiveEquipmentsProject']);
Route::get('/api/receiveWorkstationProject/{receiveNumberProject}', [ProjectoDatacontroller::class, 'receiveWorkstationProject']);
Route::get('/api/getEquipmentDetails/{receiveListEquipmentId}', [ProjectoDatacontroller::class, 'getEquipmentDetails']);
Route::get('/api/receiveAllInstallationEquipment/{receiveNumberProject}', [ProjectoDatacontroller::class, 'receiveAllInstallationEquipment']);
Route::get('/api/receveTasksWorkstationPlanning/{WorkstationId}', [CreateProjectController::class, 'receveTasksWorkstationPlanning']);
Route::get('/api/ambits/prepared{equipmentType}', [PreparedProjectController::class, 'getAmbits']);
Route::get('/api/equipment/{id}', [CreateProjectController::class, 'showJson']);
Route::get('/api/installations/', [CreateProjectController::class, 'getByUserNif']);
Route::get('/api/ambits/{equipmentType}', [CreateProjectController::class, 'getAmbits']);