<?php

use Illuminate\Support\Facades\Route;

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

Route::post('signup', 'Api\Users\UsersController@store');
Route::get('users/check-email', 'Api\Users\UsersController@checkEmail');
Route::post('passwords/reset', 'Api\Auth\PasswordsController@store');
Route::put('passwords/reset', 'Api\Auth\PasswordsController@update');

Route::group(['prefix' => 'assets'], function() {
    Route::get('/{uuid}', 'Api\Assets\RenderFileController@open');
    Route::get('/{uuid}/render', 'Api\Assets\RenderFileController@show');
    Route::get('/{uuid}/download', 'Api\Assets\RenderFileController@download');
    Route::post('/', 'Api\Assets\UploadFileController@store');
    Route::put('/{uuid}', 'Api\Assets\AssetsController@update');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/uuid', 'Api\Assets\AssetsController@destroy');
    });
});

Route::group(['prefix' => 'pages'], function() {
    Route::get('/', 'Api\Pages\PagesController@index');
    Route::get('/root', 'Api\Pages\PagesController@root');
    Route::get('/find', 'Api\Pages\PagesController@find');
    Route::get('/{id}', 'Api\Pages\PagesController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::put('/move/{id}', 'Api\Pages\PagesController@move');
        Route::put('/clone/{id}', 'Api\Pages\PagesController@clone');
        Route::delete('/{id}', 'Api\Pages\PagesController@destroy');
        Route::patch('/restore/{id}', 'Api\Pages\PagesController@restore');
    });
});

Route::group(['prefix' => 'publications'], function() {
    Route::get('/', 'Api\Publications\PublicationsController@index');
    Route::get('/find', 'Api\Publications\PublicationsController@find');
    Route::get('/{id}', 'Api\Publications\PublicationsController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::put('/published/{id}', 'Api\Publications\PublicationsController@published');
        Route::delete('/{id}', 'Api\Publications\PublicationsController@destroy');
    });
});

Route::group(['prefix' => 'object-types'], function() {
    Route::get('/', 'Api\Objects\ObjectTypesController@index');
    Route::get('/{id}', 'Api\Objects\ObjectTypesController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/{id}', 'Api\Objects\ObjectTypesController@destroy');
    });
});

Route::group(['prefix' => 'group-fields'], function() {
    Route::get('/', 'Api\Objects\GroupsController@index');
    Route::get('/{id}', 'Api\Objects\GroupsController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/{id}', 'Api\Objects\GroupsController@destroy');
    });
});

Route::group(['prefix' => 'fields'], function() {
    Route::get('/', 'Api\Objects\FieldsController@index');
    Route::get('/{id}', 'Api\Objects\FieldsController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/{id}', 'Api\Objects\FieldsController@destroy');
    });
});

Route::group(['prefix' => 'objects'], function() {
    Route::get('/', 'Api\Objects\ObjectsController@index');
    Route::get('/{id}', 'Api\Objects\ObjectsController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::put('/move/{id}', 'Api\Objects\ObjectsController@move');
        Route::delete('/{id}', 'Api\Objects\ObjectsController@destroy');
    });
});

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::put('/categories/{id}', 'Api\Registries\CategoriesController@move');
        Route::put('/entries/{id}', 'Api\Registries\EntriesController@move');
        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::group(['prefix' => 'forms'], function() {
    Route::get('/object/feedback-form-support', 'Api\Forms\FormsController@getFeedbackFormSupport');
    Route::post('/model/feedback-form-support', 'Api\Forms\FormsController@saveFeedbackFormSupport');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::get('/{target}/{type?}/{id?}', 'Api\Forms\FormsController@get');
        Route::post('/{target}/{type?}/{id?}', 'Api\Forms\FormsController@save');
    });
});

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

Route::group(['prefix' => 'advisories'], function() {
    Route::get('/', 'Api\Advisories\AdvisoriesController@index');
    Route::get('/{id}', 'Api\Advisories\AdvisoriesController@show');
    Route::get('/{id}/siblings', 'Api\Advisories\AdvisoriesController@siblings');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::delete('/{id}', 'Api\Advisories\AdvisoriesController@destroy');
    });
});

Route::group(['prefix' => 'locales'], function() {
    Route::get('/menu', 'Api\Localization\LocalesController@menu');
    Route::get('/{id}', 'Api\Localization\LocalesController@show');
    Route::group(['middleware' => ['auth:api']], function() {
        Route::get('/', 'Api\Localization\LocalesController@index');
        Route::delete('/{id}', 'Api\Localization\LocalesController@destroy');
    });
});



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::apiResource('companies', 'Api\Companies\CompaniesController');
    Route::apiResource('members', 'Api\Companies\MembersController');
    Route::apiResource('departments', 'Api\Companies\DepartmentsController');

    Route::apiResource('advisory-companies', 'Api\Advisories\AdvisoryCompaniesController');
    Route::apiResource('advisory-members', 'Api\Advisories\AdvisoryMembersController');

    Route::apiResource('applications', 'Api\Applications\ApplicationsController');

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