<?php
require_once __DIR__ . '/CloakJudgmentCache.php';

/**
 * 二次风控缓存薄封装（委托 CloakJudgmentCache，保持既有调用点兼容）。
 */
class RiskSecondaryCache
{
    const SESSION_KEY = 'cloak_judgment_cache';

    /**
     * @param array{result:string,reason?:string,fp_url?:string,ip?:string,country?:string} $payload
     */
    public static function store(array $payload)
    {
        CloakJudgmentCache::storeFromByApiRisk($payload);
    }

    /**
     * 仅返回最终缓存（partial 不视为命中）。
     *
     * @param string|null $currentIp
     * @return array|null
     */
    public static function get($currentIp = null)
    {
        return CloakJudgmentCache::getFinal($currentIp);
    }

    public static function clear()
    {
        CloakJudgmentCache::clear();
    }

    /**
     * @param array $cached
     */
    public static function applyToSession(array $cached)
    {
        CloakJudgmentCache::applyToSession($cached);
    }

    public static function hitReason()
    {
        return CloakJudgmentCache::hitReason();
    }

    /**
     * @param array $cached
     * @return array{result:bool,reason:string,link:string}
     */
    public static function toApiResponse(array $cached)
    {
        return CloakJudgmentCache::toApiResponse($cached);
    }
}
