<?php

use App\Domains\FiestaFutbolInfantil\Controllers\AccommodationController;
use App\Domains\FiestaFutbolInfantil\Controllers\CategoryVisibilityController;
use App\Domains\FiestaFutbolInfantil\Controllers\EntryController;
use App\Domains\FiestaFutbolInfantil\Controllers\FoodController;
use App\Domains\FiestaFutbolInfantil\Controllers\MerchandiseController;
use Illuminate\Support\Facades\Route;

Route::prefix('v1/adminapp/tenant')
    ->middleware(['auth:sanctum', 'adminapp.tenant'])
    ->group(function (): void {
        $visibilityRoutes = static function (string $endpoint, string $category, string $menuCode): void {
            Route::get("{$endpoint}/visibility", [CategoryVisibilityController::class, 'show'])
                ->defaults('category', $category)
                ->middleware("tenant.menu:{$menuCode}");
            Route::patch("{$endpoint}/visibility", [CategoryVisibilityController::class, 'update'])
                ->defaults('category', $category)
                ->middleware("tenant.menu:{$menuCode}");
        };

        $visibilityRoutes('entries', 'entries', 'adminapp.fiesta-futbol-infantil.entradas');
        $visibilityRoutes('foods', 'foods', 'adminapp.fiesta-futbol-infantil.comida');
        $visibilityRoutes('accommodations', 'accommodations', 'adminapp.fiesta-futbol-infantil.alojamientos');
        $visibilityRoutes('merchandise', 'merchandise', 'adminapp.fiesta-futbol-infantil.merchandising');

        Route::get('entries', [EntryController::class, 'index'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.entradas')
            ->name('adminapp.fiesta-futbol-infantil.entries.index');
        Route::post('entries', [EntryController::class, 'store'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.entradas')
            ->name('adminapp.fiesta-futbol-infantil.entries.store');
        Route::delete('entries/{entry}', [EntryController::class, 'destroy'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.entradas')
            ->name('adminapp.fiesta-futbol-infantil.entries.destroy');
        Route::get('foods', [FoodController::class, 'index'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.comida')
            ->name('adminapp.fiesta-futbol-infantil.foods.index');
        Route::post('foods', [FoodController::class, 'store'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.comida')
            ->name('adminapp.fiesta-futbol-infantil.foods.store');
        Route::delete('foods/{food}', [FoodController::class, 'destroy'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.comida')
            ->name('adminapp.fiesta-futbol-infantil.foods.destroy');
        Route::get('accommodations', [AccommodationController::class, 'index'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.alojamientos')
            ->name('adminapp.fiesta-futbol-infantil.accommodations.index');
        Route::post('accommodations', [AccommodationController::class, 'store'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.alojamientos')
            ->name('adminapp.fiesta-futbol-infantil.accommodations.store');
        Route::delete('accommodations/{accommodation}', [AccommodationController::class, 'destroy'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.alojamientos')
            ->name('adminapp.fiesta-futbol-infantil.accommodations.destroy');
        Route::get('merchandise', [MerchandiseController::class, 'index'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.merchandising')
            ->name('adminapp.fiesta-futbol-infantil.merchandise.index');
        Route::post('merchandise', [MerchandiseController::class, 'store'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.merchandising')
            ->name('adminapp.fiesta-futbol-infantil.merchandise.store');
        Route::delete('merchandise/{merchandise}', [MerchandiseController::class, 'destroy'])
            ->middleware('tenant.menu:adminapp.fiesta-futbol-infantil.merchandising')
            ->name('adminapp.fiesta-futbol-infantil.merchandise.destroy');
    });
