<?php

declare(strict_types=1);

namespace App\Framework\Redis;

use App\Framework\Cache\Driver\RedisCache;
use App\Framework\Http\Session\RedisSessionStorage;
use App\Framework\Queue\RedisQueue;

/**
 * Factory for creating Redis-based services using the connection pool
 */
final readonly class RedisFactory
{
    public function __construct(
        private RedisConnectionPool $pool
    ) {
    }

    /**
     * Create RedisCache using the cache connection
     */
    public function createCache(string $prefix = 'cache:'): RedisCache
    {
        return new RedisCache(
            connection: $this->pool->getCacheConnection(),
            prefix: $prefix
        );
    }

    /**
     * Create RedisQueue using the queue connection
     */
    public function createQueue(string $queueName = 'commands'): RedisQueue
    {
        return new RedisQueue(
            connection: $this->pool->getQueueConnection(),
            queueName: $queueName
        );
    }

    /**
     * Create RedisSessionStorage using the session connection
     */
    public function createSessionStorage(int $ttl = 3600): RedisSessionStorage
    {
        return new RedisSessionStorage(
            connection: $this->pool->getSessionConnection(),
            ttl: $ttl
        );
    }

    /**
     * Get connection pool for advanced usage
     */
    public function getPool(): RedisConnectionPool
    {
        return $this->pool;
    }
}
