<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group([
    'middleware' => 'api',
    'namespace' => 'Auth',
    'prefix' => 'auth',
], function () {
    Route::post('login', 'AuthController@login');
    Route::post('logout', 'AuthController@logout');
    Route::post('refresh', 'AuthController@refresh');
    Route::get('user', 'AuthController@user');
    // Route::post('register', 'RegisterController@register');
});

Route::group(['namespace' => 'Resources',], function () {
  Route::get('/articles/export', 'ArticleController@export')->name('articles.export');
  Route::get('/customers/export', 'CustomerController@export')->name('customers.export');
  Route::get('/expenses/export', 'ExpenseController@export')->name('expenses.export');
  Route::get('/payment-methods/export', 'PaymentMethodController@export')->name('payment-methods.export');
  Route::get('/purchase-orders/export', 'PurchaseOrderController@export')->name('purchase-orders.export');
  Route::get('/purchase-orders/{purchase_order}/export', 'PurchaseOrderDetailController@export')->name('purchase-orders-detail.export');
  Route::get('/sales/export', 'SaleController@export')->name('sales.export');
  Route::get('/units-measurement/export', 'UnitMeasurementController@export')->name('units-measurement.export');
  Route::get('/users/export', 'UserController@export')->name('users.export');
});

Route::group(['middleware' => ['jwt.auth'],], function () {
    Route::get('vue', 'IndexController@vue');
    Route::group(['namespace' => 'Resources',], function () {
        Route::resource('articles','ArticleController',['except'=>['edit','create'] ]);
        Route::delete('/customers/delete', 'CustomerController@destroyMany')->name('customers.destroyMany');
        Route::resource('customers','CustomerController',['except'=>['edit','create'] ]);
        Route::resource('expenses','ExpenseController',['except'=>['edit','create'] ]);
        Route::resource('payment-methods','PaymentMethodController',['except'=>['edit','create'] ]);
        Route::delete('/purchase-orders/delete', 'PurchaseOrderController@destroyMany')->name('purchase-orders.destroyMany');
        Route::post('/purchase-orders/{id}/email', 'PurchaseOrderController@email')->name('purchase-orders.email');
        Route::put('/purchase-orders/{id}/approved', 'PurchaseOrderController@approved')->name('purchase-orders.approved');
        Route::put('/purchase-orders/{id}/cancelled', 'PurchaseOrderController@cancelled')->name('purchase-orders.cancelled');
        Route::put('/purchase-orders/{id}/paid', 'PurchaseOrderController@paid')->name('purchase-orders.paid');
        Route::resource('purchase-orders','PurchaseOrderController',['except'=>['edit','create'] ]);
        Route::resource('purchase-orders.details','PurchaseOrderDetailController',['except'=>['edit','create'] ]);
        Route::resource('sales','SaleController',['except'=>['edit','create'] ]);
        Route::resource('sales.details','SaleDetailController',['except'=>['edit','create'] ]);
        Route::resource('units-measurement','UnitMeasurementController',['except'=>['edit','create'] ]);

        Route::put('/users/{id}/actived', 'UserController@actived')->name('users.actived');
        Route::put('/users/{id}/inactived', 'UserController@inactived')->name('users.inactived');
        Route::delete('/users/delete', 'UserController@destroyMany')->name('users.destroyMany');
        Route::resource('users','UserController',['except'=>['edit','create'] ]);
    });
});
