<?php

use App\Modules\Pilkades\Http\Controllers\AdminDesa\BannerController as AdminDesaBannerController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\CandidateController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\CandidateGalleryController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\CandidateProgramController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\CandidateVideoController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\ContactController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\CountdownController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\DashboardController as AdminDesaDashboardController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\FaqController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\ProfilDesaController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\StatisticController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\TpsController;
use App\Modules\Pilkades\Http\Controllers\AdminDesa\VoterController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\AdminDesaController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\ActivityLogController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\ApiTokenController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\AuditLogController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\BackupController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\BannerController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\DashboardController as SuperAdminDashboardController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\DesaController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\KabupatenController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\KecamatanController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\RoleController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\SettingController;
use App\Modules\Pilkades\Http\Controllers\SuperAdmin\VisitorLogController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth', 'super_admin'])
    ->prefix('super-admin')
    ->name('super-admin.')
    ->group(function () {
        Route::get('dashboard', [SuperAdminDashboardController::class, 'index'])->name('dashboard');

        Route::resource('kabupaten', KabupatenController::class)->except('show');
        Route::resource('kecamatan', KecamatanController::class)->except('show');
        Route::resource('desa', DesaController::class)->except('show');
        Route::post('desa/{desa}/publish', [DesaController::class, 'publish'])->name('desa.publish');
        Route::post('desa/{desa}/suspend', [DesaController::class, 'suspend'])->name('desa.suspend');

        Route::get('admin-desa', [AdminDesaController::class, 'index'])->name('admin-desa.index');
        Route::post('desa/{desa}/admin-desa', [AdminDesaController::class, 'store'])->name('admin-desa.store');
        Route::post('admin-desa/{user}/toggle-active', [AdminDesaController::class, 'toggleActive'])->name('admin-desa.toggle-active');
        Route::post('admin-desa/{user}/reset-password', [AdminDesaController::class, 'resetPassword'])->name('admin-desa.reset-password');

        Route::get('banner', [BannerController::class, 'index'])->name('banner.index');
        Route::post('banner', [BannerController::class, 'store'])->name('banner.store');
        Route::delete('banner/{banner}', [BannerController::class, 'destroy'])->name('banner.destroy');

        Route::get('settings', [SettingController::class, 'index'])->name('settings.index');
        Route::put('settings', [SettingController::class, 'update'])->name('settings.update');

        Route::get('visitor-log', [VisitorLogController::class, 'index'])->name('visitor-log.index');

        Route::get('backup', [BackupController::class, 'index'])->name('backup.index');
        Route::post('backup', [BackupController::class, 'store'])->name('backup.store');
        Route::get('backup/{filename}/download', [BackupController::class, 'download'])->name('backup.download');

        Route::get('activity-log', [ActivityLogController::class, 'index'])->name('activity-log.index');
        Route::get('audit-log', [AuditLogController::class, 'index'])->name('audit-log.index');

        Route::get('roles', [RoleController::class, 'index'])->name('roles.index');
        Route::put('roles/{role}', [RoleController::class, 'update'])->name('roles.update');

        Route::get('api-tokens', [ApiTokenController::class, 'index'])->name('api-tokens.index');
        Route::post('api-tokens', [ApiTokenController::class, 'store'])->name('api-tokens.store');
        Route::delete('api-tokens/{tokenId}', [ApiTokenController::class, 'destroy'])->name('api-tokens.destroy');
    });

Route::middleware(['auth', 'admin_desa'])
    ->prefix('admin-desa')
    ->name('admin-desa.')
    ->group(function () {
        Route::get('dashboard', [AdminDesaDashboardController::class, 'index'])->name('dashboard');

        Route::get('profil', [ProfilDesaController::class, 'edit'])->name('profil.edit');
        Route::put('profil', [ProfilDesaController::class, 'update'])->name('profil.update');

        Route::get('banner', [AdminDesaBannerController::class, 'index'])->name('banner.index');
        Route::post('banner', [AdminDesaBannerController::class, 'store'])->name('banner.store');
        Route::delete('banner/{banner}', [AdminDesaBannerController::class, 'destroy'])->name('banner.destroy');

        Route::get('countdown', [CountdownController::class, 'edit'])->name('countdown.edit');
        Route::put('countdown', [CountdownController::class, 'update'])->name('countdown.update');

        Route::resource('candidate', CandidateController::class)->except('show');
        Route::post('candidate/{candidate}/programs', [CandidateProgramController::class, 'store'])->name('candidate.programs.store');
        Route::delete('candidate-programs/{program}', [CandidateProgramController::class, 'destroy'])->name('candidate.programs.destroy');
        Route::post('candidate/{candidate}/gallery', [CandidateGalleryController::class, 'store'])->name('candidate.gallery.store');
        Route::delete('candidate-gallery/{galleryItem}', [CandidateGalleryController::class, 'destroy'])->name('candidate.gallery.destroy');
        Route::post('candidate/{candidate}/videos', [CandidateVideoController::class, 'store'])->name('candidate.videos.store');
        Route::delete('candidate-videos/{video}', [CandidateVideoController::class, 'destroy'])->name('candidate.videos.destroy');

        Route::get('tps', [TpsController::class, 'index'])->name('tps.index');
        Route::post('tps', [TpsController::class, 'store'])->name('tps.store');
        Route::put('tps/{tps}', [TpsController::class, 'update'])->name('tps.update');
        Route::delete('tps/{tps}', [TpsController::class, 'destroy'])->name('tps.destroy');

        Route::get('voter/import', [VoterController::class, 'showImport'])->name('voter.import.show');
        Route::post('voter/import', [VoterController::class, 'import'])->name('voter.import');
        Route::resource('voter', VoterController::class)->except('show');

        Route::get('faq', [FaqController::class, 'index'])->name('faq.index');
        Route::post('faq', [FaqController::class, 'store'])->name('faq.store');
        Route::put('faq/{faq}', [FaqController::class, 'update'])->name('faq.update');
        Route::delete('faq/{faq}', [FaqController::class, 'destroy'])->name('faq.destroy');

        Route::get('contact', [ContactController::class, 'index'])->name('contact.index');
        Route::post('contact', [ContactController::class, 'store'])->name('contact.store');
        Route::delete('contact/{contact}', [ContactController::class, 'destroy'])->name('contact.destroy');

        Route::get('statistic', [StatisticController::class, 'index'])->name('statistic.index');
    });
