<?php

declare(strict_types=1);

namespace Numinix\SeekmodoWordPress\Search;

use Numinix\SeekmodoSdk\Storage\CacheInterface;

/**
 * WordPress transient-backed cache for SDK Enhanced Native modules.
 */
final class WpTransientCache implements CacheInterface
{
    private const PREFIX = 'seekmodo_en_';

    public function get(string $key, mixed $default = null): mixed
    {
        if (!function_exists('get_transient')) {
            return $default;
        }
        $v = get_transient(self::PREFIX . $key);

        return $v === false ? $default : $v;
    }

    public function set(string $key, mixed $value, int $ttlSeconds): void
    {
        if (!function_exists('set_transient')) {
            return;
        }
        set_transient(self::PREFIX . $key, $value, $ttlSeconds);
    }

    public function delete(string $key): void
    {
        if (!function_exists('delete_transient')) {
            return;
        }
        delete_transient(self::PREFIX . $key);
    }
}
