<?php

declare(strict_types=1);

return static function (\PDO $pdo, string $prefix): void {
    if (!preg_match('/^[a-zA-Z0-9_]+$/', $prefix)) {
        throw new InvalidArgumentException('Invalid table prefix');
    }
    $t = '`' . $prefix . 'projects`';
    $pdo->exec(
        "CREATE TABLE {$t} (
            `id` int unsigned NOT NULL AUTO_INCREMENT,
            `name` varchar(255) NOT NULL,
            `site_url` varchar(2048) NOT NULL,
            `notes` text DEFAULT NULL,
            `gsc_property` varchar(512) DEFAULT NULL,
            `created_at` datetime NOT NULL,
            `updated_at` datetime NOT NULL,
            PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    );
};
