<?php
declare(strict_types=1);

const MOCKER_ADMIN_USER_TAG_KEYS = ['suspicious', 'vip', 'banned'];

function mocker_admin_tags_parse(?string $json): array
{
    if ($json === null || $json === '') {
        return [];
    }
    $d = json_decode($json, true);
    if (!is_array($d)) {
        return [];
    }
    $out = [];
    foreach ($d as $k) {
        if (!is_string($k)) {
            continue;
        }
        $k = trim($k);
        if (in_array($k, MOCKER_ADMIN_USER_TAG_KEYS, true) && !in_array($k, $out, true)) {
            $out[] = $k;
        }
    }
    sort($out);

    return $out;
}

function mocker_admin_tags_normalize_input($raw): array
{
    if (!is_array($raw)) {
        return [];
    }
    $out = [];
    foreach ($raw as $k) {
        if (!is_string($k)) {
            continue;
        }
        $k = trim($k);
        if (in_array($k, MOCKER_ADMIN_USER_TAG_KEYS, true) && !in_array($k, $out, true)) {
            $out[] = $k;
        }
    }
    sort($out);

    return $out;
}
