<?php
use App\Controllers\AuthController;
use App\Controllers\DashboardController;
use App\Controllers\ProductController;
use App\Controllers\SaleController;
use App\Controllers\ReportController;
use App\Controllers\UserController;
use App\Controllers\SearchController;
use App\Controllers\CajaController;

$routes->get('/', 'AuthController::login');
$routes->get('/login', 'AuthController::login');
$routes->post('/login', 'AuthController::authenticate');
$routes->get('/logout', 'AuthController::logout');

$routes->group('', ['filter' => 'auth'], function($routes) {
    $routes->get('/search', 'SearchController::index');
    $routes->get('/cash', 'CajaController::index');
    $routes->post('/cash/open', 'CajaController::open');
    $routes->post('/cash/add-movement', 'CajaController::addMovement');
    $routes->post('/cash/add-chica-movement', 'CajaController::addChicaMovement');
    $routes->post('/cash/close', 'CajaController::close');
    $routes->get('/cash/history', 'CajaController::history');
    $routes->get('/cash/detail/(:num)', 'CajaController::detail/$1');
    $routes->get('/dashboard', 'DashboardController::index');
    
    $routes->post('categories/save', 'ProductController::saveCategory');
    
    $routes->group('products', function($routes) {
        $routes->get('/', 'ProductController::index');
        $routes->get('create', 'ProductController::create', ['filter' => 'admin']);
        $routes->post('/', 'ProductController::store', ['filter' => 'admin']);
        $routes->get('(:num)/edit', 'ProductController::edit/$1', ['filter' => 'admin']);
        $routes->post('(:num)', 'ProductController::update/$1', ['filter' => 'admin']);
        $routes->delete('(:num)', 'ProductController::delete/$1', ['filter' => 'admin']);
    });
    
    $routes->group('sales', function($routes) {
        $routes->get('/', 'SaleController::index');
        $routes->get('create', 'SaleController::create');
        $routes->post('/', 'SaleController::store');
        $routes->get('(:num)', 'SaleController::show/$1');
        $routes->get('(:num)/edit', 'SaleController::edit/$1');
        $routes->post('(:num)', 'SaleController::update/$1');
        $routes->delete('(:num)', 'SaleController::delete/$1');
        $routes->post('restore/(:num)', 'SaleController::restore/$1');
        $routes->get('(:num)/ticket', 'SaleController::ticket/$1');
        $routes->get('(:num)/ticket-content', 'SaleController::ticketContent/$1');
        $routes->post('save-pending', 'SaleController::savePending');
        $routes->get('get-pending', 'SaleController::getPending');
        $routes->post('clear-pending', 'SaleController::clearPending');
        $routes->get('get-pending-html', 'SaleController::getPendingHtml');
    });
    
    $routes->group('reports', function($routes) {
        $routes->get('/', 'ReportController::index', ['filter' => 'admin']);
        $routes->post('generate', 'ReportController::generate', ['filter' => 'admin']);
        $routes->post('download', 'ReportController::download', ['filter' => 'admin']);
    });
    
    $routes->group('users', function($routes) {
        $routes->get('/', 'UserController::index', ['filter' => 'admin']);
        $routes->get('create', 'UserController::create', ['filter' => 'admin']);
        $routes->post('/', 'UserController::store', ['filter' => 'admin']);
        $routes->get('(:num)/edit', 'UserController::edit/$1', ['filter' => 'admin']);
        $routes->post('(:num)', 'UserController::update/$1', ['filter' => 'admin']);
        $routes->delete('(:num)', 'UserController::delete/$1', ['filter' => 'admin']);
    });
});