<?php

use App\Http\Controllers\Media\GalleryTypeController;
use App\Http\Controllers\Media\GalleryController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Media Management Routes
|--------------------------------------------------------------------------
|
| Routes for managing pictorial galleries, gallery types, and images.
| Organized in dashboard namespace with permission gates.
|
| Route Prefixes:
|   - media.gallery-types.*    — Gallery type CRUD
|   - media.galleries.*        — Gallery CRUD
|   - media.images.*           — Gallery image operations
|
| Permissions Required:
|   - view/create/edit/delete gallery types
|   - view/create/edit/delete galleries
|   - upload/edit/delete gallery images
|
*/

Route::middleware(['auth', 'verified'])
    ->prefix('dashboard/media')
    ->name('media.')
    ->group(function () {

        // ====================================================================
        // GALLERY TYPES CRUD
        // ====================================================================

        Route::resource('gallery-types', GalleryTypeController::class)
            ->names('gallery-types');

        // ====================================================================
        // GALLERIES CRUD
        // ====================================================================

        Route::resource('galleries', GalleryController::class)
            ->names('galleries');

        // Gallery Publication Actions
        Route::post('galleries/{gallery}/publish', [GalleryController::class, 'publish'])
            ->name('galleries.publish');
        Route::post('galleries/{gallery}/unpublish', [GalleryController::class, 'unpublish'])
            ->name('galleries.unpublish');

        // ====================================================================
        // GALLERY IMAGES
        // ====================================================================

        // Upload images to gallery
        Route::post('galleries/{gallery}/upload-images', [GalleryController::class, 'uploadImages'])
            ->name('images.upload');

        // Update image metadata
        Route::put('images/{image}/update-metadata', [GalleryController::class, 'updateImage'])
            ->name('images.update');

        // Delete image
        Route::delete('images/{image}', [GalleryController::class, 'deleteImage'])
            ->name('images.destroy');

        // Reorder images
        Route::post('galleries/{gallery}/reorder-images', [GalleryController::class, 'reorderImages'])
            ->name('images.reorder');

    });
