<?php

declare(strict_types=1);

namespace Apexl\Io\Cache\Dtos;

use Apexl\Dto\Dto;
use Apexl\Io\Cache\Collections\RedisCacheDriverServerConfigCollection;
use Arrayy\Arrayy;

final readonly class RedisCacheDriverConfig extends Dto
{

    public function __construct(
        public RedisCacheDriverServerConfigCollection $servers
    ) {}

    public static function fromArray(array $config): self
    {
        return new self(
            servers: RedisCacheDriverServerConfigCollection::createFromObject(
                new Arrayy($config['servers'])->map(
                    fn(array $serverConfig) => RedisCacheDriverServerConfig::fromServerConfig($serverConfig)
                )
            )
        );
    }
}
