<?php

declare(strict_types=1);

namespace Apexl\Io\Cache\Dtos;

use Apexl\Dto\Dto;
use Apexl\Io\Cache\Interfaces\CacheDriverFactoryInterface;

final readonly class CacheStreamConfigDto extends Dto
{
    public string $factory;

    /**
     * @param string $name
     * @param class-string<CacheDriverFactoryInterface> $factory
     * @param array $options
     */
    public function __construct(
        public string $name,
        string $factory,
        public array $options = [],
    ) {
        \Apexl\Io\assertInstanceOf($factory, CacheDriverFactoryInterface::class, 'cache.streams.factory');

        $this->factory = $factory;
    }


    public static function from(array $data): CacheStreamConfigDto
    {
        return new CacheStreamConfigDto(
            name: $data['name'],
            factory: $data['factory'],
            options: $data['options'] ?? [],
        );
    }
}