<?php

/*
|--------------------------------------------------------------------------
| Module Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for this module.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::group(['prefix' => Config::get('app.api_path'), 'middleware' => ['web', 'auth']], function () {
    Route::resource('task', 'App\Modules\Bookings\TaskControllerREST');
    Route::resource('tasks/repairs', 'App\Modules\Bookings\RepairsControllerREST');
    Route::resource('tasks/support', 'App\Modules\Bookings\SupportControllerREST');
    Route::resource('tasks/onsite', 'App\Modules\Bookings\OnsiteControllerRESTv1');
    Route::resource('tasks/orders', 'App\Modules\Bookings\OrdersControllerRESTv1');
    Route::resource('tasks/rma.items', 'App\Modules\Bookings\RmaItemControllerRESTv1');
    Route::resource('tasks/rma', 'App\Modules\Bookings\RmaControllerRESTv1');
    Route::resource('tasks/delivery', 'App\Modules\Bookings\DeliveryControllerRESTv1');
    Route::resource('tasks/sale-lead', 'App\Modules\Bookings\SaleLeadControllerRESTv1');
    Route::get('tasks/untouched', 'App\Modules\Bookings\TaskControllerREST@untouched');
    Route::get('keychains/types', 'App\Modules\Bookings\KeychainControllerREST@getTypes');
    Route::resource('keychains', 'App\Modules\Bookings\KeychainControllerREST');
    Route::resource('messages', 'App\Modules\Bookings\MessageControllerRESTv1');
    Route::resource('comments', 'App\Modules\Bookings\CommentControllerRESTv1');
    Route::resource('project', 'App\Modules\Bookings\ProjectControllerRESTv1');
    Route::post('parts/request-part', 'App\Modules\Bookings\controllers\api\v1\PartsControllerREST@requestPart');
    Route::post('parts/{id}/received', 'App\Modules\Bookings\controllers\api\v1\PartsControllerREST@received');
    Route::resource('parts', 'App\Modules\Bookings\controllers\api\v1\PartsControllerREST');
    Route::post('builds/request-build', 'App\Modules\Bookings\BuildsControllerRESTv1@requestBuild');
    Route::post('builds/{id}/received', 'App\Modules\Bookings\BuildsControllerRESTv1@received');
    Route::resource('builds', 'App\Modules\Bookings\BuildsControllerRESTv1');
    Route::resource('manufacturers', 'App\Modules\Bookings\ManufacturerControllerRESTv1');
    Route::resource('model-numbers', 'App\Modules\Bookings\ModelNumberControllerRESTv1');
    Route::resource('devices', 'App\Modules\Bookings\DevicesControllerRESTv1');
    Route::resource('templates', 'App\Modules\Bookings\TemplatesControllerRESTv1');
    Route::resource('template-items', 'App\Modules\Bookings\TemplateItemControllerRESTv1');
    Route::resource('feedback', 'App\Modules\Bookings\TaskFeedbackControllerREST');
    Route::get('tasks/helpers/activity', 'App\\Modules\\Bookings\\HelpersControllerREST@getActivity');
    Route::get('time-tracking/activity', 'App\\Modules\\Bookings\\TimeTrackingControllerRESTv1@getActivity');
    Route::post('task/promote/{id}', 'App\Modules\Bookings\TaskControllerREST@promote');
    Route::post('task/send-email/{id}', 'App\Modules\Bookings\TaskControllerREST@sendEmail');
    Route::post('task/addKeychain/{id}', 'App\Modules\Bookings\TaskControllerREST@addKeychain');
    Route::post('task/send-sms/{id}', 'App\Modules\Bookings\TaskControllerREST@sendSMS');
    Route::post('task/update-template-item/{id}', 'App\Modules\Bookings\TaskControllerREST@updateTemplateItem');
    Route::post('task/generate-invoice/{id}', 'App\Modules\Bookings\TaskControllerREST@generateInvoice');
    Route::post('task/create-exchange-calendar-event/{id}', 'App\Modules\Bookings\TaskControllerREST@createExchangeCalendarEvent');
    Route::post('task/update-task-and-qa/{id}', 'App\Modules\Bookings\TaskControllerREST@updateTaskAndQa');
    Route::get('time-tracking', 'App\Modules\Bookings\TimeTrackingControllerRESTv1@getIndex');
    Route::post('time-tracking/start', 'App\Modules\Bookings\TimeTrackingControllerRESTv1@postStart');
    Route::post('time-tracking/stop', 'App\Modules\Bookings\TimeTrackingControllerRESTv1@postStop');
    Route::post('bookings/email-customer', 'App\Modules\Bookings\controllers\api\v1\EmailCustomerControllerREST@emailCustomer');

    // Route::resource('sites', 'App\Modules\Clients\SitesControllerREST');
    // Route::resource('sites.users', 'App\Modules\Clients\SiteUsersControllerREST');
});

/*
|--------------------------------------------------------------------------
| Pages rendered on the server
|--------------------------------------------------------------------------
|
| This group routes are pages rendered on the server.
| All the pages require the user to be authentificated.
|
*/

Route::group(['middleware' => ['web', 'auth']], function () {
    Route::get('bookings', 'App\\Modules\\Bookings\\BookingsController@getIndex');
    Route::get('bookings/confirmation-sheet/{id}', 'App\\Modules\\Bookings\\BookingsController@getConfirmationSheet');
    Route::get('messages/{id}', 'App\Modules\Bookings\MessagesController@getIndex')
        ->where('id', '[0-9]+');
    Route::get('projects/{id}', ['as' => 'projects', 'uses' => 'App\Modules\Bookings\ProjectsController@getIndex'])
        ->where('id', '[0-9]+');
    Route::get('tasks/{id}', 'App\Modules\Bookings\TasksController@showTask');
    Route::get('tasks/{id}/print-view', 'App\Modules\Bookings\TasksController@showPrintView');
    Route::get('tasks/{id}/print-report', 'App\Modules\Bookings\TasksController@showPrintReport');
    Route::get('tasks', 'App\Modules\Bookings\TasksController@getIndex');
});

Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'tasks'], function () {
    Route::get('repairs/{id}', 'App\Modules\Bookings\RepairsController@getIndex');
    Route::get('support/{id}', 'App\Modules\Bookings\SupportController@getIndex');
    Route::get('onsite/{id}', 'App\Modules\Bookings\OnsiteController@getIndex');
    Route::get('followup/{id}', 'App\Modules\Bookings\FollowupController@getIndex');
    Route::get('qa/{id}', 'App\Modules\Bookings\QAController@getIndex');
    Route::get('orders/{id}', 'App\Modules\Bookings\OrdersController@getIndex');
    Route::get('rma/{id}', 'App\Modules\Bookings\RmaController@getIndex');
    Route::get('sale-lead/{id}', 'App\Modules\Bookings\SaleLeadController@getIndex');
});

//Does not require auth. Requires valid pin and job id
Route::group(['prefix' => Config::get('app.api_path')], function () {
    Route::get('tasks/checkstatususingpin/{id}/{pin}/{token}', 'App\Modules\Bookings\RepairsControllerREST@checkStatusFromPin');
    Route::get('comments/postcommentusingpin/{id}/{pin}/{comment}', 'App\Modules\Bookings\CommentControllerRESTv1@postCommentUsingPin');
    Route::get('tasks/deteletokenusingid/{id}/{token}', 'App\Modules\Bookings\RepairsControllerREST@deteleTokenUsingId');
});
