<?php

use Illuminate\Support\Facades\Route;

Route::get('ping', 'Api\PingController@index');

Route::get('assets/{uuid}', 'Api\Assets\RenderFileController@open');
Route::get('assets/{uuid}/render', 'Api\Assets\RenderFileController@show');
Route::get('assets/{uuid}/download', 'Api\Assets\RenderFileController@download');

Route::post('register', 'Api\Auth\RegisterController@store');
Route::post('passwords/reset', 'Api\Auth\PasswordsController@store');
Route::put('passwords/reset', 'Api\Auth\PasswordsController@update');

Route::get('/check-email', 'Api\Auth\RegisterController@checkEmail');

Route::get('pages', 'Api\Pages\PagesController@index');
Route::get('pages/root', 'Api\Pages\PagesController@root');
Route::get('pages/find', 'Api\Pages\PagesController@find');
Route::get('pages/{id}', 'Api\Pages\PagesController@show');

Route::get('publications', 'Api\Publications\PublicationsController@index');
Route::get('publications/find', 'Api\Publications\PublicationsController@find');
Route::get('publications/{id}', 'Api\Publications\PublicationsController@show');

Route::apiResource('object-types', 'Api\Objects\ObjectTypesController');

Route::group(['prefix' => 'forms'], function() {
    Route::get('/{target}/{type?}/{id?}', 'Api\Forms\FormsController@get');
    Route::post('/{target}/{type?}/{id?}', 'Api\Forms\FormsController@save');
});


Route::group(['prefix' => 'registries'], function() {
    Route::get('/categories', 'Api\Registries\CategoriesController@index');
    Route::get('/categories/{id}', 'Api\Registries\CategoriesController@show');
    Route::get('/entries', 'Api\Registries\EntriesController@index');
    Route::get('/entries/{id}', 'Api\Registries\EntriesController@show');
    Route::get('/operations', 'Api\Registries\OperationsController@index');
    Route::get('/operations/{id}', 'Api\Registries\OperationsController@show');
    Route::get('/', 'Api\Registries\RegistriesController@index');
    Route::get('/{id}', 'Api\Registries\RegistriesController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/categories/{id}', 'Api\Registries\CategoriesController@destroy');
        Route::delete('/entries/{id}', 'Api\Registries\EntriesController@destroy');
        Route::delete('/operations/{id}', 'Api\Registries\OperationsController@destroy');
    });
});

Route::get('filters/{type}', 'Api\Forms\FormsController@filters');

Route::group(['middleware' => ['auth:api']], function() {
	Route::apiResource('users', 'Api\Users\UsersController');
	Route::apiResource('roles', 'Api\Users\RolesController');

	Route::get('permissions', 'Api\Users\PermissionsController@index');

    Route::group(['prefix' => 'me'], function() {
        Route::get('/', 'Api\Users\ProfileController@index');
        Route::put('/', 'Api\Users\ProfileController@update');
        Route::patch('/', 'Api\Users\ProfileController@update');
        Route::put('/password', 'Api\Users\ProfileController@updatePassword');

        Route::group(['prefix' => 'notifications'], function() {
            Route::get('/', 'Api\NotificationsController@list');
            Route::get('/count', 'Api\NotificationsController@count');
        });
    });

    Route::group(['prefix' => 'assets'], function() {
        Route::post('/', 'Api\Assets\UploadFileController@store');
    });

    Route::put('objects/move/{id}', 'Api\Objects\ObjectsController@move');
    Route::apiResource('objects', 'Api\Objects\ObjectsController');

    Route::get('dadata/{inn}', 'Api\Companies\CompaniesController@getDataByInn');

    Route::put('publications/published/{id}', 'Api\Publications\PublicationsController@published');
    Route::delete('publications/{id}', 'Api\Publications\PublicationsController@destroy');

    Route::apiResource('companies', 'Api\Companies\CompaniesController');
    Route::apiResource('members', 'Api\Companies\MembersController');
    Route::apiResource('departments', 'Api\Companies\DepartmentsController');

    Route::apiResource('advisories', 'Api\Advisories\AdvisoriesController');
    Route::get('advisories/{id}/siblings', 'Api\Advisories\AdvisoriesController@siblings');
    Route::apiResource('advisory-companies', 'Api\Advisories\AdvisoryCompaniesController');
    Route::apiResource('advisory-members', 'Api\Advisories\AdvisoryMembersController');

});