<?php

declare(strict_types=1);

namespace App\Framework\Cache\Driver;

use App\Framework\Cache\CacheDriver;
use App\Framework\Cache\CacheItem;
use App\Framework\Cache\CacheKey;
use App\Framework\Cache\CacheResult;
use App\Framework\Cache\Contracts\Scannable;

final class NullCache implements CacheDriver, Scannable
{
    public function get(CacheKey ...$keys): CacheResult
    {
        if (empty($keys)) {
            return CacheResult::empty();
        }

        $items = array_map(fn ($key) => CacheItem::miss($key), $keys);

        return CacheResult::fromItems(...$items);
    }

    public function set(CacheItem ...$items): bool
    {
        return true;
    }

    public function has(CacheKey ...$keys): array
    {
        if (empty($keys)) {
            return [];
        }

        $results = [];
        foreach ($keys as $key) {
            $keyString = (string)$key;
            $results[$keyString] = false;
        }

        return $results;
    }

    public function forget(CacheKey ...$keys): bool
    {
        return true;
    }

    public function clear(): bool
    {
        return true;
    }

    // === Scannable Interface Implementation ===

    public function scan(string $pattern, int $limit = 1000): array
    {
        // NullCache has no data, so scan returns empty array
        return [];
    }

    public function scanPrefix(string $prefix, int $limit = 1000): array
    {
        // NullCache has no data, so prefix scan returns empty array
        return [];
    }

    public function getAllKeys(int $limit = 1000): array
    {
        // NullCache has no keys
        return [];
    }

    public function getScanPerformance(): array
    {
        return [
            'efficient' => true,
            'max_recommended_keys' => 0,
            'estimated_time_per_1000_keys' => 0.0, // No time needed for empty results
        ];
    }
}
