<?php

declare(strict_types=1);

namespace CloudXM\NFe\DTOs;

/**
 * API Config DTO
 * 
 * Represents API configuration in tenant config response
 */
class ApiConfig
{
    public function __construct(
        public string $version,
        public string $base_url,
        public EndpointsConfig $endpoints
    ) {}

    /**
     * Create from API response array
     */
    public static function fromArray(array $data): self
    {
        $endpoints = isset($data['endpoints']) && is_array($data['endpoints'])
            ? EndpointsConfig::fromArray($data['endpoints'])
            : new EndpointsConfig('/v1/invoices', '/v1/tenants');

        return new self(
            version: $data['version'] ?? 'v1',
            base_url: $data['base_url'] ?? '',
            endpoints: $endpoints
        );
    }
}
