<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->setAutoRoute(false);

$routes->get('/', 'Home::index');
$routes->get('login', 'AuthController::index');
$routes->post('login', 'AuthController::login');

// Rutas públicas (sin auth) para validación QR
$routes->get('verify/(:segment)', 'VerifyController::show/$1');
$routes->get('verify/(:segment)/pdf', 'VerifyController::pdf/$1');

$routes->group('', ['filter' => 'auth'], static function ($routes) {
    $routes->get('logout', 'AuthController::logout');
    $routes->get('dashboard', 'DashboardController::index');

    // Clientes
    $routes->get('clients', 'ClientController::index');
    $routes->get('clients/create', 'ClientController::create');
    $routes->post('clients', 'ClientController::store');
    $routes->get('clients/(:num)/edit', 'ClientController::edit/$1');
    $routes->post('clients/(:num)/update', 'ClientController::update/$1');
    $routes->post('clients/(:num)/delete', 'ClientController::delete/$1');

    // Plantillas de inspección
    $routes->get('inspection-templates', 'InspectionTemplateController::index');
    $routes->get('inspection-templates/create', 'InspectionTemplateController::create');
    $routes->post('inspection-templates', 'InspectionTemplateController::store');
    $routes->get('inspection-templates/(:num)/edit', 'InspectionTemplateController::edit/$1');
    $routes->post('inspection-templates/(:num)/update', 'InspectionTemplateController::update/$1');
    $routes->post('inspection-templates/(:num)/items', 'InspectionTemplateController::saveItems/$1');
    $routes->post('inspection-templates/(:num)/delete', 'InspectionTemplateController::delete/$1');

    // Inspecciones
    $routes->get('inspections', 'InspectionController::index');
    $routes->get('inspections/create', 'InspectionController::create');
    $routes->post('inspections', 'InspectionController::store');
    $routes->get('inspections/(:num)', 'InspectionController::show/$1');
    $routes->get('inspections/(:num)/edit', 'InspectionController::edit/$1');
    $routes->post('inspections/(:num)/autosave', 'InspectionController::autosave/$1');
    $routes->post('inspections/(:num)/finalize', 'InspectionController::finalize/$1');
    $routes->post('inspections/(:num)/duplicate', 'InspectionController::duplicate/$1');
    $routes->post('inspections/(:num)/attachments', 'InspectionController::uploadAttachment/$1');
    $routes->post('inspections/(:num)/delete', 'InspectionController::delete/$1');
    $routes->get('inspections/(:num)/pdf', 'InspectionController::pdf/$1');

    // Reportes
    $routes->get('reports', 'ReportController::index');
    $routes->get('reports/create', 'ReportController::create');
    $routes->post('reports', 'ReportController::store');
    $routes->get('reports/(:num)', 'ReportController::show/$1');
    $routes->get('reports/(:num)/edit', 'ReportController::edit/$1');
    $routes->get('reports/(:num)/photos/(:num)', 'ReportController::photo/$1/$2');
    $routes->post('reports/(:num)/update', 'ReportController::update/$1');
    $routes->post('reports/(:num)/photos', 'ReportController::uploadPhoto/$1');
    $routes->post('reports/(:num)/photos/(:num)/delete', 'ReportController::deletePhoto/$1/$2');
    $routes->post('reports/(:num)/delete', 'ReportController::delete/$1');
    $routes->get('reports/(:num)/pdf', 'ReportController::pdf/$1');

    // Actas de entrega
    $routes->get('delivery-notes', 'DeliveryNoteController::index');
    $routes->get('delivery-notes/create', 'DeliveryNoteController::create');
    $routes->post('delivery-notes', 'DeliveryNoteController::store');
    $routes->get('delivery-notes/(:num)', 'DeliveryNoteController::show/$1');
    $routes->get('delivery-notes/(:num)/photos/(:num)', 'DeliveryNoteController::photo/$1/$2');
    $routes->post('delivery-notes/(:num)/update', 'DeliveryNoteController::update/$1');
    $routes->post('delivery-notes/(:num)/duplicate', 'DeliveryNoteController::duplicate/$1');
    $routes->post('delivery-notes/(:num)/photos', 'DeliveryNoteController::uploadPhoto/$1');
    $routes->post('delivery-notes/(:num)/photos/(:num)/delete', 'DeliveryNoteController::deletePhoto/$1/$2');
    $routes->post('delivery-notes/(:num)/delete', 'DeliveryNoteController::delete/$1');
    $routes->get('delivery-notes/(:num)/pdf', 'DeliveryNoteController::pdf/$1');

    // Plantillas de acta
    $routes->get('delivery-note-templates', 'DeliveryNoteTemplateController::index');
    $routes->get('delivery-note-templates/create', 'DeliveryNoteTemplateController::create');
    $routes->post('delivery-note-templates', 'DeliveryNoteTemplateController::store');
    $routes->get('delivery-note-templates/(:num)/edit', 'DeliveryNoteTemplateController::edit/$1');
    $routes->post('delivery-note-templates/(:num)/update', 'DeliveryNoteTemplateController::update/$1');
    $routes->post('delivery-note-templates/(:num)/delete', 'DeliveryNoteTemplateController::delete/$1');

    // Firmas
    $routes->post('signatures/upload', 'SignatureController::upload');

    // Branding (heredado de Dume)
    $routes->post('settings/access', 'SettingsController::unlock');
    $routes->get('settings/branding', 'SettingsController::index');
    $routes->post('settings/branding', 'SettingsController::update');
    $routes->post('settings/branding/lock', 'SettingsController::lock');

});
