<?php

declare(strict_types=1);

/**
 * Speed up pages search/filter when device+country dimensions exist.
 *
 * @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 . 'gsc_daily_page`';

    // Supports WHERE property_id + device + country + date range, and prefix LIKE on page.
    try { $pdo->exec("ALTER TABLE {$t} ADD KEY `idx_prop_dev_ctr_date_page` (`property_id`, `device`, `country`, `date`, `page`(191))"); } catch (\Throwable) {}
};

