<?php

use App\Modules\Admin\ActivityLog\Controllers\ActivityLogController;
use App\Modules\Admin\IntegrationsHealth\Controllers\IntegrationsHealthPageController;
use App\Modules\Admin\Operations\Controllers\BusinessMetricsController;
use App\Modules\Admin\Operations\Controllers\SupportImpersonationController;
use App\Modules\Admin\Operations\Controllers\TenantDiagnosticsController;
use App\Modules\Admin\SystemHealth\Controllers\SystemHealthPageController;
use App\Modules\Admin\Tenancy\Controllers\DashboardController;
use App\Modules\Admin\Tenancy\Controllers\ModuleController;
use App\Modules\Admin\Tenancy\Controllers\PlanController;
use App\Modules\Admin\Tenancy\Controllers\TenantBillingRecordController;
use App\Modules\Admin\Tenancy\Controllers\TenantController;
use App\Modules\Admin\Tenancy\Controllers\TenantLifecycleController;
use Illuminate\Support\Facades\Route;

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

        Route::get('system-health', [SystemHealthPageController::class, 'index'])
            ->name('system-health.index');

        Route::get('integrations-health', [IntegrationsHealthPageController::class, 'index'])
            ->name('integrations-health.index');

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

        Route::get('operations/business-metrics', [BusinessMetricsController::class, 'index'])
            ->name('operations.business-metrics');

        Route::get('operations/tenants/{tenant}/diagnostics', [TenantDiagnosticsController::class, 'show'])
            ->name('operations.tenants.diagnostics');

        Route::post('operations/impersonations', [SupportImpersonationController::class, 'store'])
            ->name('operations.impersonations.store');

        Route::get('operations/impersonations/consume', [SupportImpersonationController::class, 'consume'])
            ->name('operations.impersonations.consume');

        Route::post('operations/impersonations/{session}/revoke', [SupportImpersonationController::class, 'revoke'])
            ->name('operations.impersonations.revoke');

        Route::post('tenants/{tenant}/lifecycle/suspend', [TenantLifecycleController::class, 'suspend'])
            ->name('tenants.lifecycle.suspend');

        Route::post('tenants/{tenant}/lifecycle/resume', [TenantLifecycleController::class, 'resume'])
            ->name('tenants.lifecycle.resume');

        Route::post('tenants/{tenant}/lifecycle/activate', [TenantLifecycleController::class, 'activate'])
            ->name('tenants.lifecycle.activate');

        Route::post('tenants/{tenant}/lifecycle/archive', [TenantLifecycleController::class, 'archive'])
            ->name('tenants.lifecycle.archive');

        Route::post('tenants/{tenant}/billing/failed-payment', [TenantBillingRecordController::class, 'storeFailedPayment'])
            ->name('tenants.billing.failed-payment');

        Route::resource('modules', ModuleController::class)
            ->except(['show']);

        Route::resource('plans', PlanController::class)
            ->except(['show']);

        Route::resource('tenants', TenantController::class)
            ->except(['show']);
    });
