<?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::get('/schedule/events','ScheduleController@apiIndex');
Route::get('/schedule/events/modal/{id}/{db_type}','ScheduleController@loadModal');

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

    /** Calendar Route */
    Route::post('/calendar/generate', 'CalendarController@generate');
    Route::post('/calendar_ecc/generate', 'ECCController@generateCalendar');
    Route::post('/calendar/loadDay', 'CalendarController@show');
    Route::post('/calendar/delete', 'CalendarController@delete');

    Route::get('/schedule/events/modal/full/{id}/{db_type}','ScheduleController@loadModalFull');
    Route::get('/schedule/events/add/modal/{type}/{date}','ScheduleController@loadModalDefautType');
    Route::post('/schedule/event/delete/{id}','ScheduleController@delete');

    /** Picture */
    Route::post('/picture/delete/{id}','PictureController@destroy');

    /** Message Route */
    Route::post('/message/delete', 'MessageController@destroy');

    /** User Route */
    Route::post('/user/delete', 'UserController@destroy');
    Route::get('/user/list', 'UserController@apiList');

    /** Inventory Route */
    Route::post('/item/delete', 'ItemController@destroy');

    /** Config Route */
    Route::post('/config/general/save', 'ConfigController@update');
    Route::post('/config/activity/delete', 'ComplementaryActivityController@destroy');

    Route::get('/user/perm/{id}', function($id) {
        $user = \App\User::find($id);
        return $user->getPerm("schedule_edit");
    });
});
Route::get('/admin/ping', function(){
    $users = \App\User::all();
    $schedules = \App\Schedule::all();
    $oups = false;

    foreach ($users as $user) {
        if($user == null){
            $oups = true;
        }
    }
    foreach ($schedules as $schedule) {
        if($schedule == null){
            $oups = true;
        }
    }
    
    if ($oups) {
        return "oups";
    } else {
        return "pong";
    }
});
Route::get('/ecc/ping', function(){
    $users = \App\User::all();
    $schedules = \App\Schedule::all();
    $oups = false;

    foreach ($users as $user) {
        if($user == null){
            $oups = true;
        }
    }
    foreach ($schedules as $schedule) {
        if($schedule == null){
            $oups = true;
        }
    }
    
    if ($oups) {
        return "oups";
    } else {
        return "pong";
    }
});
