<?php

use App\Modules\Integrations\Platform\Controllers\V1\BiometricIngestController;
use App\Modules\Integrations\Platform\Controllers\V1\HealthController;
use App\Modules\Integrations\Platform\Controllers\V1\IntegrationWebhookController;
use Illuminate\Support\Facades\Route;

Route::prefix('v1')
    ->name('api.v1.')
    ->middleware(['api', 'throttle:api_public'])
    ->group(function (): void {
        Route::get('/health', HealthController::class)->name('health');

        Route::middleware(['api.token', 'throttle:api_v1'])->group(function (): void {
            Route::post('/biometric/devices/{device}/punches', BiometricIngestController::class)
                ->middleware(['api.scopes:biometric.ingest'])
                ->name('biometric.ingest');

            Route::get('/webhooks', [IntegrationWebhookController::class, 'index'])
                ->middleware(['api.scopes:webhooks.read'])
                ->name('webhooks.index');
            Route::post('/webhooks', [IntegrationWebhookController::class, 'store'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.store');
            Route::get('/webhooks/{webhook}', [IntegrationWebhookController::class, 'show'])
                ->middleware(['api.scopes:webhooks.read'])
                ->name('webhooks.show');
            Route::patch('/webhooks/{webhook}', [IntegrationWebhookController::class, 'update'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.update');
            Route::delete('/webhooks/{webhook}', [IntegrationWebhookController::class, 'destroy'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.destroy');
            Route::post('/webhooks/{webhook}/rotate-secret', [IntegrationWebhookController::class, 'rotateSecret'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.rotate-secret');
            Route::post('/webhooks/{webhook}/test', [IntegrationWebhookController::class, 'test'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.test');
            Route::post('/webhooks/{webhook}/toggle', [IntegrationWebhookController::class, 'toggle'])
                ->middleware(['api.scopes:webhooks.write'])
                ->name('webhooks.toggle');
        });
    });

