<?php

declare(strict_types=1);

namespace app\common\facade;

use app\common\library\Token as TokenLibrary;

/**
 * Token 门面类（Webman 等价实现，替代 ThinkPHP Facade）
 * @see TokenLibrary
 * @method static array get(string $token)
 * @method static bool set(string $token, string $type, int $userId, ?int $expire = null)
 * @method static bool check(string $token, string $type, int $userId)
 * @method static bool delete(string $token)
 * @method static bool clear(string $type, int $userId)
 * @method static void tokenExpirationCheck(array $token)
 */
class Token
{
    private static ?TokenLibrary $instance = null;

    private static function getInstance(): TokenLibrary
    {
        if (self::$instance === null) {
            self::$instance = new TokenLibrary();
        }
        return self::$instance;
    }

    public static function get(string $token): array
    {
        return self::getInstance()->get($token);
    }

    public static function set(string $token, string $type, int $userId, ?int $expire = null): bool
    {
        return self::getInstance()->set($token, $type, $userId, $expire);
    }

    public static function check(string $token, string $type, int $userId): bool
    {
        return self::getInstance()->check($token, $type, $userId);
    }

    public static function delete(string $token): bool
    {
        return self::getInstance()->delete($token);
    }

    public static function clear(string $type, int $userId): bool
    {
        return self::getInstance()->clear($type, $userId);
    }

    public static function tokenExpirationCheck(array $token): void
    {
        self::getInstance()->tokenExpirationCheck($token);
    }
}
