<?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::post('login', 'UserController@login');
Route::post('register', 'UserController@register');

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::middleware('auth:api')->group( function() {
    Route::get('/users/{user}/workorders', 'Api\UsersController@workOrders');

    Route::get('/workorders/{workOrder}/asset', 'Api\WorkOrdersController@asset');
    Route::get('/workorders/{workOrder}/notes', 'Api\WorkOrdersController@notes');
    Route::get('/workorders/{workOrder}', 'Api\WorkOrdersController@show');
    Route::put('/workorders/{workOrder}', 'Api\WorkOrdersController@update');

    Route::post('/workorders/notes', 'Api\WorkOrderNotesController@store');
    Route::put('/workorders/notes/{workOrderNote}', 'Api\WorkOrderNotesController@update');

    Route::get('/assets/{asset}/credentials', 'Api\AssetsController@credentials');
    Route::put('/assets/{asset}', 'Api\AssetsController@update');

    Route::get('/stores', 'Api\StoresController@index');
    Route::get('/stores/{store}', 'Api\StoresController@show');

    Route::post('/credentials', 'Api\CredentialsController@store');
    Route::put('/credentials/{credential}', 'Api\CredentialsController@update');
    Route::delete('/credentials/{credential}', 'Api\CredentialsController@destroy');
    Route::get('credentials/descriptions', 'Api\CredDescController@index');

});