<?php

use App\Http\Controllers\Api\V1\ApiAuthController;
use App\Http\Controllers\Api\V1\FavouriteController;
use App\Http\Controllers\Api\V1\FcmController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| 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::domain(config('app.url'))->group(function () {
    //The refresh token middle ware was lefe here because it only has any effect if the header is received
    $openMiddleWares = ['checkApiValidRequest', 'api_version', 'checkApiLanguage', 'refreshJwtToken'];
    $securedMiddleWares = array_merge($openMiddleWares, ['auth:api']);

    Route::group(
        array(
            'middleware' => $securedMiddleWares
        ),
        function () {

            Route::post('/logout', [ApiAuthController::class, 'logout']);
            Route::post('/refresh', [ApiAuthController::class, 'refresh']);
            Route::post('/profile', [ApiAuthController::class, 'profile']);
            Route::post('/update-firebase-token', [ApiAuthController::class, 'updateFcmToken']);

            Route::post('/favourite', [FavouriteController::class, 'store']);
            Route::get('/favourites', [FavouriteController::class, 'index']);
            Route::delete('/favourite/{id}', [FavouriteController::class, 'destroy']);

            Route::post('/subscribe-fcm-topic', [FcmController::class, 'subscribeToTopic']);
            Route::post('/unsubscribe-fcm-topic', [FcmController::class, 'unsubscribeToTopic']);
            Route::post('/unsubscribe-fcm-topic-all', [FcmController::class, 'unsubscribeToAllTopics']);
            Route::get('/fcm-topics', [FcmController::class, 'getTopics']);

            Route::post('/delete-user', [ApiAuthController::class, 'remove']);
        }
    );


    Route::group(
        array(
            'middleware' => $openMiddleWares
        ),
        function () {

            Route::get('structure', 'StructureController@index');
            Route::get('entry_contents', 'StructureController@entryContents');



            Route::get('cities', 'CityController@index');
            Route::get('cities/{id}', 'CityController@show');

            Route::get('locations', 'LocationController@index');
            Route::get('locations/{id}', 'LocationController@show');

            Route::get('exhibitions', 'ExhibitionController@index');
            Route::get('exhibitions/status', 'ExhibitionController@separated');
            Route::get('exhibitions/{id}', 'ExhibitionController@show');
            Route::get('exhibitions/tag/{tagid}', 'ExhibitionController@bytag');

            Route::get('artists', 'ArtistController@index');
            Route::get('artists/{id}', 'ArtistController@show');
            Route::get('artists/tag/{tagid}', 'ArtistController@bytag');

            Route::get('news', 'NewsItemController@index');
            Route::get('news/{id}', 'NewsItemController@show');

            Route::get('news-categories', 'NewsCategoryController@index');
            Route::get('news-categories/{id}', 'NewsCategoryController@show');

            Route::get('collections', 'CollectionController@index');
            Route::get('collections/{id}', 'CollectionController@show');

            Route::get('tags', 'TagController@index');

            Route::get('search', 'SearchController@index');

            Route::post('/register', [ApiAuthController::class, 'register']);
            Route::post('/login', [ApiAuthController::class, 'login']);
            Route::post('forgot-password', [ApiAuthController::class, 'forgotPassword']);
            Route::post('reset-password', [ApiAuthController::class, 'resetPassword'])->name('password.reset');

            Route::post('newsletter-subscription', 'NewsletterSubscriptionController@subscribe');
            Route::post('newsletter-unsubscribe', 'NewsletterSubscriptionController@unsubscribe');



            Route::get('debug', 'DebugController@index');
        }
    );
});
