<?php

use App\Http\Controllers\Admin\ActivityLogController;
use App\Http\Controllers\Admin\ClientController;
use App\Http\Controllers\Admin\ContactMessageController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\GalleryController;
use App\Http\Controllers\Admin\MediaController;
use App\Http\Controllers\Admin\NavigationController;
use App\Http\Controllers\Admin\PageContentController;
use App\Http\Controllers\Admin\PartnerController;
use App\Http\Controllers\Admin\ServiceController;
use App\Http\Controllers\Admin\SettingsController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Middleware\EnsureAdminPasswordIsChanged;
use App\Http\Middleware\EnsureAdminUserIsActive;
use Illuminate\Support\Facades\Route;

Route::prefix('admin')
    ->name('admin.')
    ->middleware(['auth', EnsureAdminUserIsActive::class, EnsureAdminPasswordIsChanged::class, 'can:access-admin'])
    ->group(function (): void {
        Route::get('/', DashboardController::class)->name('dashboard');

        Route::prefix('contenus')->name('content.')->group(function (): void {
            Route::get('/', [PageContentController::class, 'index'])->name('index');
            Route::get('/accueil', [PageContentController::class, 'editSlug'])->defaults('slug', 'home')->name('home');
            Route::get('/a-propos', [PageContentController::class, 'editSlug'])->defaults('slug', 'about')->name('about');
            Route::get('/services', [PageContentController::class, 'editSlug'])->defaults('slug', 'services-page')->name('services-page');
            Route::get('/galerie', [PageContentController::class, 'editSlug'])->defaults('slug', 'gallery-page')->name('gallery-page');
            Route::get('/contact', [PageContentController::class, 'editSlug'])->defaults('slug', 'contact-page')->name('contact-page');
            Route::patch('/{page}', [PageContentController::class, 'update'])->name('update');
            Route::post('/{page}/publier', [PageContentController::class, 'publish'])->name('publish');
        });

        Route::prefix('services')->name('services.')->group(function (): void {
            Route::get('/', [ServiceController::class, 'index'])->name('index');
            Route::get('/ajouter', [ServiceController::class, 'create'])->name('create');
            Route::post('/', [ServiceController::class, 'store'])->name('store');
            Route::post('/actions-groupees', [ServiceController::class, 'bulk'])->name('bulk');
            Route::get('/{service}/modifier', [ServiceController::class, 'edit'])->name('edit');
            Route::patch('/{service}', [ServiceController::class, 'update'])->name('update');
            Route::post('/{service}/publier', [ServiceController::class, 'publish'])->name('publish');
            Route::patch('/{service}/visibilite', [ServiceController::class, 'toggle'])->name('toggle');
            Route::post('/{service}/dupliquer', [ServiceController::class, 'duplicate'])->name('duplicate');
            Route::post('/{service}/archiver', [ServiceController::class, 'archive'])->name('archive');
            Route::delete('/{service}', [ServiceController::class, 'destroy'])->name('destroy');
        });

        Route::prefix('partenaires')->name('partners.')->group(function (): void {
            Route::get('/', [PartnerController::class, 'index'])->name('index');
            Route::get('/ajouter', [PartnerController::class, 'create'])->name('create');
            Route::post('/', [PartnerController::class, 'store'])->name('store');
            Route::post('/actions-groupees', [PartnerController::class, 'bulk'])->name('bulk');
            Route::get('/{partner}/modifier', [PartnerController::class, 'edit'])->name('edit');
            Route::patch('/{partner}', [PartnerController::class, 'update'])->name('update');
            Route::patch('/{partner}/visibilite', [PartnerController::class, 'toggle'])->name('toggle');
            Route::post('/{partner}/archiver', [PartnerController::class, 'archive'])->name('archive');
            Route::delete('/{partner}', [PartnerController::class, 'destroy'])->name('destroy');
        });

        Route::prefix('clients')->name('clients.')->group(function (): void {
            Route::get('/', [ClientController::class, 'index'])->name('index');
            Route::get('/ajouter', [ClientController::class, 'create'])->name('create');
            Route::post('/', [ClientController::class, 'store'])->name('store');
            Route::post('/actions-groupees', [ClientController::class, 'bulk'])->name('bulk');
            Route::get('/{client}/modifier', [ClientController::class, 'edit'])->name('edit');
            Route::patch('/{client}', [ClientController::class, 'update'])->name('update');
            Route::patch('/{client}/visibilite', [ClientController::class, 'toggle'])->name('toggle');
            Route::post('/{client}/archiver', [ClientController::class, 'archive'])->name('archive');
            Route::delete('/{client}', [ClientController::class, 'destroy'])->name('destroy');
        });

        Route::prefix('galerie')->name('gallery.')->group(function (): void {
            Route::get('/', [GalleryController::class, 'index'])->name('index');
            Route::get('/archives', [GalleryController::class, 'archiveIndex'])->name('archives');
            Route::get('/ajouter', [GalleryController::class, 'create'])->name('create');
            Route::post('/', [GalleryController::class, 'store'])->name('store');
            Route::post('/actions-groupees', [GalleryController::class, 'bulk'])->name('bulk');
            Route::get('/{item}/modifier', [GalleryController::class, 'edit'])->name('edit');
            Route::patch('/{item}', [GalleryController::class, 'update'])->name('update');
            Route::post('/{item}/publier', [GalleryController::class, 'publish'])->name('publish');
            Route::patch('/{item}/visibilite', [GalleryController::class, 'toggle'])->name('toggle');
            Route::post('/{item}/archiver', [GalleryController::class, 'archive'])->name('archive');
            Route::post('/{item}/restaurer', [GalleryController::class, 'restore'])->name('restore');
            Route::delete('/{item}/definitif', [GalleryController::class, 'forceDestroy'])->name('force-destroy');
        });

        Route::prefix('medias')->name('media.')->group(function (): void {
            Route::get('/', [MediaController::class, 'index'])->name('index');
            Route::post('/', [MediaController::class, 'store'])->name('store');
            Route::patch('/{media}', [MediaController::class, 'update'])->name('update');
            Route::delete('/{media}', [MediaController::class, 'destroy'])->name('destroy');
            Route::delete('/{media}/definitif', [MediaController::class, 'forceDestroy'])->name('force-destroy');
        });

        Route::prefix('messages')->name('messages.')->group(function (): void {
            Route::get('/', [ContactMessageController::class, 'index'])->name('index');
            Route::post('/actions-groupees', [ContactMessageController::class, 'bulk'])->name('bulk');
            Route::get('/{message}', [ContactMessageController::class, 'show'])->name('show');
            Route::patch('/{message}/statut', [ContactMessageController::class, 'updateStatus'])->name('status');
            Route::post('/{message}/reponses', [ContactMessageController::class, 'storeReply'])->name('replies.store');
            Route::post('/{message}/repondre', [ContactMessageController::class, 'sendReply'])->name('replies.send');
            Route::post('/{message}/archiver', [ContactMessageController::class, 'archive'])->name('archive');
            Route::delete('/{message}', [ContactMessageController::class, 'destroy'])->name('destroy');
        });

        Route::get('/navigation', [NavigationController::class, 'index'])->name('navigation.index');
        Route::patch('/navigation', [NavigationController::class, 'update'])->name('navigation.update');

        Route::prefix('parametres')->name('settings.')->group(function (): void {
            Route::get('/', [SettingsController::class, 'general'])->name('general');
            Route::patch('/', [SettingsController::class, 'updateGeneral'])->name('general.update');
            Route::get('/coordonnees', [SettingsController::class, 'contact'])->name('contact');
            Route::patch('/coordonnees', [SettingsController::class, 'updateContact'])->name('contact.update');
            Route::get('/seo', [SettingsController::class, 'seo'])->name('seo');
            Route::patch('/seo', [SettingsController::class, 'updateSeo'])->name('seo.update');
            Route::get('/email', [SettingsController::class, 'email'])->name('email');
            Route::patch('/email', [SettingsController::class, 'updateEmail'])->name('email.update');
        });

        Route::prefix('utilisateurs')->name('users.')->group(function (): void {
            Route::get('/', [UserController::class, 'index'])->name('index');
            Route::get('/ajouter', [UserController::class, 'create'])->name('create');
            Route::post('/', [UserController::class, 'store'])->name('store');
            Route::get('/{user}/modifier', [UserController::class, 'edit'])->name('edit');
            Route::patch('/{user}', [UserController::class, 'update'])->name('update');
            Route::patch('/{user}/statut', [UserController::class, 'toggle'])->name('toggle');
            Route::post('/{user}/reset-password', [UserController::class, 'sendPasswordReset'])->name('reset-password');
            Route::delete('/{user}', [UserController::class, 'destroy'])->name('destroy');
        });

        Route::get('/journal-activite', [ActivityLogController::class, 'index'])->name('activity.index');
    });
