<?php

use Laravel\Lumen\Routing\Router;

$router->get('/', function () use ($router) {
    return 'Public View';
});

$router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']], function () use ($router) {
    $router->group(['prefix' => '/users'], function () use ($router) {
        $router->get(   '/',     ['as' => 'users.all',    'uses' => 'UsuariosController@all',    'middleware' => ['role:admin|global_admin']]);
        $router->get(   '/{id}', ['as' => 'users.get',    'uses' => 'UsuariosController@get',    'middleware' => ['role:admin|global_admin', 'is_colega']]);
        $router->post(  '/',     ['as' => 'users.create', 'uses' => 'UsuariosController@create', 'middleware' => ['role:admin|global_admin']]);
        $router->put(   '/{id}', ['as' => 'users.update', 'uses' => 'UsuariosController@update', 'middleware' => ['role:admin|global_admin', 'is_colega']]);
        $router->delete('/{id}', ['as' => 'users.delete', 'uses' => 'UsuariosController@delete', 'middleware' => ['role:admin|global_admin', 'is_colega']]);
        $router->get(   '/{id}/restaurantes/',             ['as' => 'users.get_restaurantes',       'uses' => 'UsuariosController@getRestaurantes',      'middleware' => ['role:admin|global_admin', 'is_colega']]);
        $router->put(   '/{id}/restaurantes/{restaurant}', ['as' => 'users.add_to_restaurant',      'uses' => 'UsuariosController@addToRestaurant',      'middleware' => ['role:admin|global_admin', 'is_colega']]);
        $router->delete('/{id}/restaurantes/{restaurant}', ['as' => 'users.remove_from_restaurant', 'uses' => 'UsuariosController@removeFromRestaurant', 'middleware' => ['role:admin|global_admin', 'is_colega']]);
    });

    $router->group(['prefix' => '/restaurantes'], function () use ($router) {
        $router->get(   '/',     ['as' => 'restaurant.all',    'uses' => 'RestaurantesController@all']);
        $router->get(   '/{id}', ['as' => 'restaurant.get',    'uses' => 'RestaurantesController@get']);
        $router->post(  '/',     ['as' => 'restaurant.create', 'uses' => 'RestaurantesController@create', 'middleware' => ['role:global_admin']]);
        $router->put(   '/{id}', ['as' => 'restaurant.update', 'uses' => 'RestaurantesController@update', 'middleware' => ['role:admin|global_admin']]);
        $router->delete('/{id}', ['as' => 'restaurant.delete', 'uses' => 'RestaurantesController@delete', 'middleware' => ['role:global_admin']]);

        $router->get(   '/{restaurante_id}/canales-venta',      ['as' => 'canales-venta.all',    'uses' => 'CanalesVentaController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/canales-venta/{id}', ['as' => 'canales-venta.get',    'uses' => 'CanalesVentaController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/canales-venta',      ['as' => 'canales-venta.create', 'uses' => 'CanalesVentaController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/canales-venta/{id}', ['as' => 'canales-venta.update', 'uses' => 'CanalesVentaController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/canales-venta/{id}', ['as' => 'canales-venta.delete', 'uses' => 'CanalesVentaController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/sectores',      ['as' => 'sectores.all',    'uses' => 'SectoresController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/sectores/{id}', ['as' => 'sectores.get',    'uses' => 'SectoresController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/sectores',      ['as' => 'sectores.create', 'uses' => 'SectoresController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/sectores/{id}', ['as' => 'sectores.update', 'uses' => 'SectoresController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/sectores/{id}', ['as' => 'sectores.delete', 'uses' => 'SectoresController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/zonas-produccion',            ['as' => 'zonas-produccion.all',    'uses' => 'ZonasProduccionController@all',    'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/zonas-produccion/{id}',       ['as' => 'zonas-produccion.get',    'uses' => 'ZonasProduccionController@get',    'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/zonas-produccion/{id}/users', ['as' => 'zonas-produccion.users',  'uses' => 'ZonasProduccionController@users',  'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/zonas-produccion',            ['as' => 'zonas-produccion.create', 'uses' => 'ZonasProduccionController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/zonas-produccion/{id}',       ['as' => 'zonas-produccion.update', 'uses' => 'ZonasProduccionController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/zonas-produccion/{id}',       ['as' => 'zonas-produccion.delete', 'uses' => 'ZonasProduccionController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/categorias',      ['as' => 'categorias.all',    'uses' => 'CategoriasController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/categorias/{id}', ['as' => 'categorias.get',    'uses' => 'CategoriasController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/categorias',      ['as' => 'categorias.create', 'uses' => 'CategoriasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/categorias/{id}', ['as' => 'categorias.update', 'uses' => 'CategoriasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/categorias/{id}', ['as' => 'categorias.delete', 'uses' => 'CategoriasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/proveedores',      ['as' => 'proveedores.all',    'uses' => 'ProveedoresController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/proveedores/{id}', ['as' => 'proveedores.get',    'uses' => 'ProveedoresController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/proveedores',      ['as' => 'proveedores.create', 'uses' => 'ProveedoresController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/proveedores/{id}', ['as' => 'proveedores.update', 'uses' => 'ProveedoresController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/proveedores/{id}', ['as' => 'proveedores.delete', 'uses' => 'ProveedoresController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/ingredientes',      ['as' => 'ingredientes.all',    'uses' => 'IngredientesController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/ingredientes/{id}', ['as' => 'ingredientes.get',    'uses' => 'IngredientesController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/ingredientes',      ['as' => 'ingredientes.create', 'uses' => 'IngredientesController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/ingredientes/{id}', ['as' => 'ingredientes.update', 'uses' => 'IngredientesController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/ingredientes/{id}', ['as' => 'ingredientes.delete', 'uses' => 'IngredientesController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/productos',      ['as' => 'productos.all',    'uses' => 'ProductosController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/productos/{id}', ['as' => 'productos.get',    'uses' => 'ProductosController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/productos',      ['as' => 'productos.create', 'uses' => 'ProductosController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/productos/{id}', ['as' => 'productos.update', 'uses' => 'ProductosController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/productos/{id}', ['as' => 'productos.delete', 'uses' => 'ProductosController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/productos/{producto_id}/ingredientes/',                 ['as' => 'productos.receta.all',                'uses' => 'RecetasController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/productos/{producto_id}/ingredientes/{ingrediente_id}', ['as' => 'productos.receta.get',                'uses' => 'RecetasController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/productos/{producto_id}/ingredientes/{ingrediente_id}', ['as' => 'productos.receta.add_ingrediente',    'uses' => 'RecetasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/productos/{producto_id}/ingredientes/{ingrediente_id}', ['as' => 'productos.receta.update_ingrediente', 'uses' => 'RecetasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/productos/{producto_id}/ingredientes/{ingrediente_id}', ['as' => 'productos.receta.remove_ingrediente', 'uses' => 'RecetasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/compras',                                    ['as' => 'compras.all',                 'uses' => 'ComprasController@all', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/compras/{id}',                               ['as' => 'compras.get',                 'uses' => 'ComprasController@get', 'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/compras',                                    ['as' => 'compras.create',              'uses' => 'ComprasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/compras/{id}',                               ['as' => 'compras.update',              'uses' => 'ComprasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/compras/{id}',                               ['as' => 'compras.delete',              'uses' => 'ComprasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/compras/{id}/ingredientes',                  ['as' => 'compras.ingredientes.get',    'uses' => 'ComprasController@getIngredientes',  'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/compras/{id}/ingredientes/{ingrediente_id}', ['as' => 'compras.ingredientes.add',    'uses' => 'ComprasController@addIngrediente',   'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/compras/{id}/ingredientes/{ingrediente_id}', ['as' => 'compras.ingredientes.delete', 'uses' => 'ComprasController@deleteIngrediente','middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.get',    'uses' => 'FacturasController@get',    'middleware' => ['in_restaurante']]);
        $router->post(  '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.create', 'uses' => 'FacturasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->put(   '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.update', 'uses' => 'FacturasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
        $router->delete('/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.delete', 'uses' => 'FacturasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);

        $router->get(   '/{restaurante_id}/bodega/ingresos',                     ['as' => 'bodega.ingresos',                'uses' => 'BodegaController@ingresos',                'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/ingresos/{ingrediente_id}',    ['as' => 'bodega.ingresos_ingrediente',    'uses' => 'BodegaController@ingresos_ingrediente',    'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/egresos',                      ['as' => 'bodega.egresos',                 'uses' => 'BodegaController@egresos',                 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/egresos/{ingrediente_id}',     ['as' => 'bodega.egresos_ingrediente',     'uses' => 'BodegaController@egresos_ingrediente',     'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/movimientos',                  ['as' => 'bodega.movimientos',             'uses' => 'BodegaController@movimientos',             'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/movimientos/{ingrediente_id}', ['as' => 'bodega.movimientos_ingrediente', 'uses' => 'BodegaController@movimientos_ingrediente', 'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/actual',                       ['as' => 'bodega.actual',                  'uses' => 'BodegaController@actual',                  'middleware' => ['in_restaurante']]);
        $router->get(   '/{restaurante_id}/bodega/actual/{ingrediente_id}',      ['as' => 'bodega.actual_ingrediente',      'uses' => 'BodegaController@actual_ingrediente',      'middleware' => ['in_restaurante']]);
    });
});
