<?php

declare(strict_types=1);

if (!defined('ABSPATH')) {
    define('ABSPATH', dirname(__DIR__, 2) . '/');
}

$GLOBALS['feca_bootstrap_actions'] = [];

function get_option($key, $default = null)
{
    if ($key !== \FecaMailshots\Admin\SetupAdminPage::OPTION_KEY) {
        return $default;
    }
    return [
        'db_host' => 'invalid-host.local.test',
        'db_port' => '3306',
        'db_user' => 'mailshots',
        'db_password' => 'secret',
        'mailshots_db_name' => 'mailshots',
        'members_db_name' => 'members',
        'fen_db_name' => 'fen',
    ];
}

function add_action(string $hook, callable $callback): void
{
    if (!isset($GLOBALS['feca_bootstrap_actions'][$hook])) {
        $GLOBALS['feca_bootstrap_actions'][$hook] = [];
    }
    $GLOBALS['feca_bootstrap_actions'][$hook][] = $callback;
}

function add_menu_page(...$args): void
{
}

function add_submenu_page(...$args): void
{
}

require dirname(__DIR__, 2) . '/feca_mailshots_plugin/feca_mailshots_plugin.php';

$actions = $GLOBALS['feca_bootstrap_actions'];
if (!isset($actions['admin_post_feca_mailshots_data_sources_api'], $actions['admin_post_feca_mailshots_setup_save'])) {
    fwrite(STDERR, "Expected normal handlers to register without touching the database\n");
    exit(1);
}

echo "Bootstrap full setup no DB touch regression test passed\n";
