<?php

declare(strict_types=1);

/**
 * M4 Google Search Console properties (sites).
 *
 * @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`';
    $pdo->exec(
        "CREATE TABLE {$t} (
            `id` int unsigned NOT NULL AUTO_INCREMENT,
            `site_url` varchar(2048) NOT NULL,
            `site_type` varchar(32) NOT NULL,
            `permission_level` varchar(64) NOT NULL,
            `fetched_at` datetime NOT NULL,
            PRIMARY KEY (`id`),
            UNIQUE KEY `site_url_unique` (`site_url`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
    );
};

