<?php

use App\Http\Controllers\Api\AircraftApiController;
use App\Http\Controllers\Api\AirlineApiController;
use App\Http\Controllers\Api\UserApiController;
use App\Http\Controllers\FeedController;
use App\Http\Controllers\HomePageController;
use Illuminate\Support\Facades\Route;

Route::domain(config('app.api_domain'))->group(function () {

    /* Public Routes */
    Route::get('/', function () {
        return response()->json(['message' => 'Welcome to the FlightsGoneBy API']);
    });

    Route::prefix('internal')->middleware('sanctum.or.trusted')->group(function () {
        Route::get('/user/{user}/flights', [UserApiController::class, 'viewableFlights'])->name('api.user.flights');
        Route::get('/user/{user}/flights/departed', [UserApiController::class, 'viewableDepartedFlights'])->name('api.user.flights.departed');
        Route::get('/flights/most-recent', [HomePageController::class ,'mostRecentFlights'])->name('home-page.most-recent-flights');
        Route::get('/feed/following', [FeedController::class ,'following'])->name('feed.following');
        Route::get('/feed/following-flights', [FeedController::class ,'followingFlights'])->name('feed.following-flights');
    });


    /* Image Routes */
    Route::prefix('airline')->controller(AirlineApiController::class)->group(function () {
        Route::get('{internalName}/logo/tail', 'getLogoByInternalName')->name('airline.logo.tail');
        Route::get('{airlineInternalName}/livery/{aircraftDesignator}', 'getLivery')->name('airline.livery');
    });

    Route::prefix('aircraft')->controller(AircraftApiController::class)->group(function () {
        Route::get('{aircraftDesignator}/livery', 'getLivery')->name('aircraft.livery');
    });


    /*Authenticated Routes*/
    Route::middleware('auth:sanctum')->group(function () {
        Route::prefix('airline')->controller(AirlineApiController::class)->group(function () {
            Route::get('{internalName}', 'get')->name('airline.show');
            Route::get('code/{code}', 'getByCode')->name('airline.code.index');
        });

        Route::prefix('user')->controller(UserApiController::class)->group(function () {
            Route::get('/flights/next', 'nextFlight')->name('api.user.flights.next');
        });
    });


});
