<?php

declare(strict_types=1);

namespace Apexl\Io\Cache\Dtos;

use Apexl\Dto\Dto;

final readonly class RedisCacheDriverServerConfig extends Dto
{
    private const int DEFAULT_PORT = 6379;

    public function __construct(
        public string $server,
        public int $port = self::DEFAULT_PORT,
    ) {}

    public static function fromServerConfig(array $config): RedisCacheDriverServerConfig
    {
        return new self(
            server: $config['server'],
            port: $config['port'] ?? self::DEFAULT_PORT,
        );
    }
}
