<?php

declare(strict_types=1);

namespace PhpWA\AppState;

use InvalidArgumentException;

final class AppStateName
{
    public const CRITICAL_BLOCK = 'critical_block';
    public const CRITICAL_UNBLOCK_LOW = 'critical_unblock_low';
    public const REGULAR_LOW = 'regular_low';
    public const REGULAR_HIGH = 'regular_high';
    public const REGULAR = 'regular';

    /** @return list<string> */
    public static function all(): array
    {
        return [self::CRITICAL_BLOCK, self::CRITICAL_UNBLOCK_LOW, self::REGULAR_HIGH, self::REGULAR, self::REGULAR_LOW];
    }

    public static function isValid(string $name): bool { return in_array($name, self::all(), true); }

    public static function assert(string $name): void
    {
        if (!self::isValid($name)) { throw new InvalidArgumentException('Unknown WhatsApp app-state collection.'); }
    }

    public static function macCollection(string $name): string
    {
        self::assert($name);
        return 'app_state_mac_' . $name;
    }

    private function __construct() {}
}
