<?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;



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

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

// Route::get('/api/receiveEquipmentsExecutionProject/{receiveNumberProject}',[ExecutionProjectController::class,'receiveEquipmentsExecutionProject'])->name('receiveEquipmentsExecutionProject');
Route::get('/api/receiveEquipmentsProject/{receiveNumberProject}',[ProjectoDatacontroller::class,'receiveEquipmentsProject']);
Route::get('/api/receiveWorkstationProject/{receiveNumberProject}',[ProjectoDatacontroller::class,'receiveWorkstationProject' ]);



Route::get('user-data', [PreparedProjectController::class, 'getData1'])->name('getData');
Route::get('/api/ambits/prepared{equipmentType}', [PreparedProjectController::class,'getAmbits']);



Route::get('preparedProject/{ProjectId}',[PreparedProjectController::class,'PreparedProject'])->name('preparedProject');

Route::get('EditProjectForArticulated',[PreparedProjectController::class,'editProjectForArticulated'])->name('EditProjectForArticulated');

// Route::get('test',[CreateProjectController::class,'index'] )->name('test');
route::get('finishCreatingProject/{numberProject}',[CreateProjectController::class,'finishCreatingProject'])->name('finishCreatingProject');


route::get('testDataTables',[CreateProjectController::class,'testDataTables'])->name('testDataTables');

Route::get('workstationsAssociationTasks', [CreateProjectController::class,'workstationsAssociationTasks'])->name('workstationsAssociationTasks');

route::get('AddNomenclatureWorkstation', [CreateProjectController::class,'AddNomenclatureWorkstation'])->name('AddNomenclatureWorkstation');

route::get('removeProjectEquipment', [CreateProjectController::class,'removeProjectEquipment'])->name('removeProjectEquipment');

Route::delete('deleteWorkstation/{name}', [CreateProjectController::class, 'deleteWorkstation'])->name('deleteWorkstation');


route::get('idiota',function(){
    return view('recebeTestProgressBar');
});

Route::get('/api/equipment/{id}', [CreateProjectController::class,'showJson']);

Route::post('/EditEquipmentsProjects',[CreateProjectController::class,'EditEquipmentsProjects'])->name('EditEquipmentsProjects');

// Vai ser unicamente a pagina de criacao de uma obra 
Route::get('/createProject', [CreateProjectController::class,'createProjectForStep1'])->name('createProject');
Route::post('/newProject1', [CreateProjectController::class,'processStep1'])->name('processStep1');

route::post('/createWorkStations',[CreateProjectController::class,'createWorkStations'])->name('createWorkStations');

Route::get('/test1/{id}', [CreateProjectController::class,'showStep1'])->name('test1');
Route::get('/test2/{id}', [CreateProjectController::class,'showStep2'])->name('test2');
Route::get('/test3/{id}', [CreateProjectController::class,'showStep3'])->name('test3');

Route::post('test1', [CreateProjectController::class,'EditprocessStep1'])->name('EditprocessStep1');
Route::post('/test2', [CreateProjectController::class,'processStep2'])->name('processStep2');

Route::post('/test2CreateEquipment',[CreateProjectController::class,'createEquipmentManual'])->name('test2CreateEquipment');



Route::post('/test3', [CreateProjectController::class,'processStep3']);

Route::get('testando',function(){
    return view('codePronto');
});

Route::delete('/removeEquipment/{id}', [CreateProjectController::class, 'removePendingEquipment'])->name('removeEquipment');
Route::post('CreateNewEquipmentFromPendingEquipment/{id}', [CreateProjectController::class, 'CreateNewEquipmentFromPendingEquipment'])->name('CreateNewEquipmentFromPendingEquipment');
// Ainda nao funciona corretamente
// Route::get('/receiveEquipmentID/{equipment}',[CreateProjectController::class,'receiveIdEquipment'])->name('receiveIdEquipment');


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

/*
|--------------------------------------------------------------------------
| User_Type (Super_Administrador)
|--------------------------------------------------------------------------
|*** Routes unique access to the Super_Administrator, due to its sensitive data.
|
|
*/
Route::middleware(['auth', 'verified', 'checksuperadmin'])->group(function () {
    Route::get('usersProfiles/{id}', [userController::class, 'UserProfile'])->name('usersProfiles');
    Route::post('enviar-formulario', [FormController::class, 'enviarEmail'])->name('enviar.formulario');


    /*
    |--------------------------------------------------------------------------
    | CRUD - users
    |--------------------------------------------------------------------------
    |
    | Definition routes to implement the CRUD model
    |
    */
    Route::get('users/ListUsers', [userController::class, 'ListUsers'])->name('users.list');
    
    Route::get('users/ListCompanies', [userController::class, 'ListCompanies'])->name('users.company');

    Route::get('users/{id}', [userController::class, 'show'])->name('users.Show');
    Route::get('users/{id}/edit', [userController::class, 'edit'])->name('users.edit');
    Route::put('users/{user}', [userController::class, 'update'])->name('users.update');
    Route::delete('users/{user}', [UserController::class, 'destroy'])->name('users.destroy');
    

    /*
    |--------------------------------------------------------------------------
    | Create Users with Super Admin
    |--------------------------------------------------------------------------
    |
    | 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('/CreateUsers', [Pending_UserController::class, 'ListPendingUsers'])->name('CreateUsers');
    Route::get('/CreateUsers/{id}', [Pending_UserController::class, 'ShowFormUser'])->name('ShowPendingUser');
    Route::post('formulario/receive', [Pending_UserController::class, 'store'])->name('criarUser');
    Route::get('formulario', function () {
        return view('email/FormAdmin');
    })->name('formulario');
});


/*
|--------------------------------------------------------------------------
| Create Users with Super Admin
|--------------------------------------------------------------------------
|
| 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::middleware(['auth', 'verified','checkUserType'])->group(function () {
//      // Rotas protegidas que exigem verificação de e-mail
//      Route::get('/', [ProjectoDatacontroller::class,('HomePage')])->name('home');
//      Route::get('enterWorkstation',[ExecutionProjectController::class,'enterWorkstation'])->name('enterWorkstation');
//  });

 Route::middleware(['auth','checkUserType'])->group(function () {
    // Rotas protegidas que exigem verificação de e-mail
    Route::get('/', [ProjectoDatacontroller::class,('HomePage')])->name('home');
    Route::get('enterWorkstation',[ExecutionProjectController::class,'enterWorkstation'])->name('enterWorkstation');
});



/*
|--------------------------------------------------------------------------
| Template Excel
|--------------------------------------------------------------------------
|
| 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('/template', function () {
     $filePath = public_path('templateExcel/FinalTemplate1.xlsx');
     $fileName = 'Valves_Template.xlsx';

    return response()->download($filePath, $fileName);
})->name('download');


/*
|--------------------------------------------------------------------------
| Create Project
|--------------------------------------------------------------------------
|
| 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::post('createProject1',[CreateProjectController::class,'createProject'])->name('createProject1');

// Route::get('createProject', [CreateProjectController::class,'listCompanies'])->name('createProject');

// Route::post('createProject1',[CreateProjectController::class,'createProject'])->name('createProject1');



Route::post('/create-equipament-project', [CreateProjectController::class,'createEquipamentProject'])->name('createEquipamentProject');

 /* Api */
Route::get('/api/installations/', [CreateProjectController::class, 'getByUserNif']);
Route::get('/api/ambits/{equipmentType}',[CreateProjectController::class, 'getAmbits']);

Route::get('/equipments/{id}/attributes', [CreateProjectController::class, 'getAttributes']);


Route::post('/register', [CustomRegistrationController::class, 'store'])->name('register');

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

Route::get('/receiveThisShit', function () {
    return redirect()->route('test');
})->name('verification.notice');


Route::get('/testExcel', function(){
    return view('createProjectExcel');
})->name('testExcel');



/*
|--------------------------------------------------------------------------
| CRUD -Equipaments
|--------------------------------------------------------------------------
|
| 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('manageAssets',[ProjectoDatacontroller::class,'ManageAssets'])->name('manageAssets');


/*
|--------------------------------------------------------------------------
| CRUD -Instalation
|--------------------------------------------------------------------------
|
| 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('manageAssets',[ProjectoDatacontroller::class,'ManageAssets'])->name('manageAssets');

//  Mostrar instalacao click
Route::get('units/{id}',[ProjectoDatacontroller::class,'showUnit'])->name('showUnit');







 // Rotas protegidas que exigem verificação de e-mail e user_type Super_Admin
    // Route::get('/register', [RegisteredUserController::class, 'create'])
    //     ->name('register');
    // Route::post('/register', [RegisteredUserController::class, 'store'])


// Route::get('/test-email', function () {
//     $to = 'ygbanzato@isptgroup.com';
//     $subject = 'Test Email from Laravel';

//     $message = Mail::raw('This is a test email from Laravel.', function ($message) use ($to, $subject) {
//         $message->to($to)->subject($subject);
//     });

//     if ($message) {
//         return 'Email sent successfully';
//     } else {
//         return 'Failed to send email';
//     }
// });

// Route::get('formulario', function () {
//     return view('email/FormAdmin');
// })->name('formulario');


// Route::post('formulario/receive', [Pending_UserController::class, 'store'])->name('criarUser');


   // Route::get('/', function () {
    //     return view('Admin/index');
    // })->name('home');

    // Route::get('formulario', function () {
    //     return view('email/formAdmin');
    // })->name('formulario');

    //   Route::get('/email/notice', function (EmailVerificationRequest $request) {
//       return view('auth.verify-email');
//   })->middleware(['auth'])->name('verification.notice');
