<?php

declare(strict_types=1);

/**
 * M5 activation toggles for Google properties.
 *
 * @return callable(PDO, string): void
 */
return static function (\PDO $pdo, string $prefix): void {
    if (!preg_match('/^[a-zA-Z0-9_]+$/', $prefix)) {
        throw new InvalidArgumentException('Invalid table prefix');
    }
    $t = '`' . $prefix . 'google_properties`';

    // Add columns if missing (best-effort).
    try { $pdo->exec("ALTER TABLE {$t} ADD COLUMN `is_enabled` tinyint(1) NOT NULL DEFAULT 0"); } catch (\Throwable) {}
    try { $pdo->exec("ALTER TABLE {$t} ADD COLUMN `enabled_at` datetime NULL"); } catch (\Throwable) {}
};

