<?php

use App\Http\Controllers\AlmacenController;
use App\Http\Controllers\ArticuloController;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\HomeController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PermissionController;
use App\Http\Controllers\CategoriaController;
use App\Http\Controllers\ProveedorController;
use App\Http\Controllers\ClienteController;
use App\Http\Controllers\IngresoController;
use App\Http\Controllers\VentaController;
use App\Http\Controllers\EmpresaController;
use App\Http\Controllers\ProductoController;
use App\Http\Controllers\ReportController;
use App\Models\Almacen;

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

Auth::routes();

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

Route::get('/export', [ArticuloController::class, 'export'])->name('export');

Route::post('/importar', [ArticuloController::class, 'importar'])->name('importar');

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

Route::get('/acerca', function () {
    return view('acerca');
});
Route::get('ayuda', function () {
    return view('ayuda');
});


Route::group(['middleware' => ['auth']], function () {

    Route::resource('users', UserController::class);
    Route::resource('roles', RoleController::class);
    Route::resource('permissions', PermissionController::class);
    Route::resource('almacen/categoria', CategoriaController::class);
    Route::resource('almacen/articulo', ProductoController::class);
    Route::resource('compras/proveedor', ProveedorController::class);
    Route::resource('compras/ingreso', IngresoController::class);
    Route::resource('ventas/cliente', ClienteController::class);
    Route::resource('ventas/venta', VentaController::class);
    Route::resource('almacen/empresa', EmpresaController::class);
    Route::resource('almacen/almacenes', AlmacenController::class);

    Route::get('almacen/almacenes/agregar-producto/{id}', [AlmacenController::class, 'agregar_almacen'])->name('almacenes.agregar_producto');

    Route::get('almacen/almacenes/producto/{nombre}', [AlmacenController::class, 'obtener_producto']);

    // Route::post('almacen/almacenes/almacen-productos', [AlmacenController::class, 'agregar_producto_almacen']);

    Route::post('/agregar_producto_almacen', [AlmacenController::class, 'agregar_producto_almacen']);

    Route::post('/almacen/almacenes/traspasar_producto_almacen/{id}', [AlmacenController::class, 'traspasar_producto']);
    
    Route::get('almacen/almacenes/almacen_producto/{nombre_almacen}', [AlmacenController::class, 'mostrar_producto_almacen']);

    Route::get('almacen/almacenes/contar_productos/{nombre_almacen}', [AlmacenController::class, 'contarProducto_almacen']);

    Route::put('/compras/ingreso/anular_producto/{id}', [IngresoController::class, 'anular']);

    //Reportes

    Route::get('ventas/reports_day', [ReportController::class, 'reports_day'])->name('reports.day');
    Route::get('ventas/reports_date', [ReportController::class, 'reports_date'])->name('reports.date');
    Route::post('ventas/report_results', [ReportController::class, 'report_results'])->name('report.results');

    Route::get('reportecategorias', [CategoriaController::class, 'reporte']);
    Route::get('reporteusuarios', [UserController::class, 'reporte']);
    Route::get('reporteproductos', [ProductoController::class, 'reporte']);
    Route::get('reporteclientes', [ClienteController::class, 'reporte']);
    Route::get('reporteproveedores', [ProveedorController::class, 'reporte']);
    Route::get('reporteventas', [VentaController::class, 'reporte']);
    Route::get('reporteventa/{id}', [VentaController::class, 'reportec']);
    Route::get('reporteingresos', [IngresoController::class, 'reporte']);
    Route::get('reporteingreso/{id}', [IngresoController::class, 'reportec']);
    Route::get('reportecentro', [EmpresaController::class, 'reporte']);

    //Para rutas no direccionadas
    Route::get('/{slug?}', [HomeController::class, 'index']);
});