<?php
declare(strict_types=1);

require_once __DIR__ . '/../subscribers_lib.php';

$cases = [
    '1M/1M' => '1M/1M',
    '1M/1M 1M/1M 1M/1M 10/10' => '1M/1M',
    "  2m/4m\t4m/8m   2m/4m  10/10  " => '2M/4M',
    'custom-profile-value' => 'custom-profile-value',
    '' => '',
];

foreach ($cases as $input => $expected) {
    $actual = subs_rate_limit_display($input);
    if ($actual !== $expected) {
        fwrite(STDERR, "FAIL input={$input} expected={$expected} actual={$actual}\n");
        exit(1);
    }
}

$speedCases = [
    [['speed_name' => '4M'], 'PPPOE-2M', '4M'],
    [[], 'PPPOE-2M', '2M'],
    [['speed_name' => '—'], 'PPPoE_16m', '16M'],
    [[], 'custom-profile', 'custom-profile'],
    [[], '', ''],
];

foreach ($speedCases as [$row, $profile, $expected]) {
    $actual = subs_speed_display($row, $profile);
    if ($actual !== $expected) {
        fwrite(STDERR, "FAIL speed profile={$profile} expected={$expected} actual={$actual}\n");
        exit(1);
    }
}

echo "subscriber_rate_limit_display_test: OK\n";
