<?php

/**
 * Gets all the mails configured via `config/campaignmonitor.php`, ending up in routes
 * like 'api.campaignmonitor.transactional.dummy'.
 *
 * If you need a quick way to debug/see these routes:
 * `php artisan route:list | grep api.campaignmonitor.transactional`
 *
 * For convenience/testing reasons, a GET route is also added. Although you would need to disable sanctum to really
 * hit these in the browser.
 */

use Illuminate\Support\Facades\Route;
use Tricks\CampaignMonitor\Http\Controllers\CampaignMonitorController;

Route::middleware('api') // Assigns a middleware _group_, not a single middleware
    ->prefix('api/campaignmonitor/transactional/')
    ->name('api.campaignmonitor.transactional.')
    ->group(function () {
        collect(config('campaignmonitor.transactional.mails'))->keys()->each(function ($mailSlug) {
            Route::match(
                ['get', 'post'], strtolower($mailSlug),
                [CampaignMonitorController::class, 'sendTransactional']
            )
                ->name($mailSlug);
        });
    });
