<?php

use App\Http\Controllers\Auth\RegisterClinicController;
use App\Http\Controllers\Landing\LandingController;
use Illuminate\Support\Facades\Route;

/*
| Central domain — marketing site, clinic signup, platform-staff login.
| Tenant + admin route files are registered in bootstrap/app.php.
*/
Route::domain(config('tenancy.central_domain'))->group(function () {
    Route::get('/', [LandingController::class, 'index'])->name('landing');

    Route::middleware('guest')->group(function () {
        Route::get('/register', [RegisterClinicController::class, 'create'])->name('register');
        Route::post('/register', [RegisterClinicController::class, 'store'])
            ->middleware('throttle:5,1')
            ->name('register.store');
    });

    // WhatsApp Cloud API webhook (provider-facing).
    Route::get('/whatsapp/webhook', [\App\Http\Controllers\Public\WhatsAppWebhookController::class, 'verify']);
    Route::post('/whatsapp/webhook', [\App\Http\Controllers\Public\WhatsAppWebhookController::class, 'handle']);
});

// Signed media for WhatsApp PDF attachments (central domain, signature = auth).
Route::get('/wa-media/{message}', [\App\Http\Controllers\Public\WaMediaController::class, 'show'])
    ->domain(config('tenancy.central_domain'))->name('wa.media');
