<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\ClientController;
use App\Http\Controllers\ProductoController;
use App\Http\Controllers\CotizacionController;
use App\Http\Controllers\ReportController;



Route::get('/', function () {
    return view('auth/login');
});

Auth::routes();

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

Route::middleware('auth')->group(function () {

  Route::get('/auditoria', [\App\Http\Controllers\AuditController::class, 'index'])
        ->name('auditoria.index');
    Route::view('about', 'about')->name('about');
    Route::get('users', [\App\Http\Controllers\UserController::class, 'index'])->name('users.index');
    Route::get('profile', [\App\Http\Controllers\ProfileController::class, 'show'])->name('profile.show');
    Route::put('profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');

    Route::resource('companies', CompanyController::class);
    Route::resource('users', UserController::class);
    Route::post('/cotizaciones', [CotizacionController::class, 'store']);
    Route::resource('productos', ProductoController::class);
    Route::resource('cotizaciones', CotizacionController::class);
    Route::resource('roles', RoleController::class);
        Route::resource('clientes', ClientController::class);
      
});

Route::resource('permissions', PermissionController::class)
    ->middleware(['auth']);

    Route::get('roles/{role}/permissions', [RoleController::class, 'permissions'])
    ->name('roles.permissions')
    ->middleware('auth');

Route::post('roles/{role}/permissions', [RoleController::class, 'syncPermissions'])
    ->name('roles.permissions.sync')
    ->middleware('auth');

    Route::resource('clients', ClientController::class)
    ->middleware('auth');

    Route::prefix('cotizacion')->group(function() {
    Route::get('{token}', [CotizacionController::class, 'showCliente'])
        ->name('cotizaciones.showCliente');

    Route::get('{token}/aprobar', [CotizacionController::class, 'aprobar'])
        ->name('cotizaciones.aprobar');

    Route::get('{token}/rechazar', [CotizacionController::class, 'rechazar'])
        ->name('cotizaciones.rechazar');
});

Route::get('/cotizaciones/{cotizacion}/pdf', 
    [App\Http\Controllers\CotizacionController::class, 'pdf']
)->name('cotizaciones.pdf');


    Route::get('/reports/sales', [ReportController::class, 'sales'])->name('reports.sales');
Route::get('/reports/sales/pdf', [ReportController::class, 'salesPdf'])->name('reports.sales.pdf');