<?php

declare(strict_types=1);

/**
 * M2 settings storage (plaintext for now; encryption in S2.2).
 *
 * @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');
    }
    $table = '`' . $prefix . 'settings`';
    $pdo->exec(
        "CREATE TABLE {$table} (
            `name` varchar(191) NOT NULL,
            `value_text` longtext NULL,
            `updated_at` datetime NOT NULL,
            PRIMARY KEY (`name`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    );
};

