<?php

declare(strict_types=1);

namespace CloudXM\NFe\DTOs;

/**
 * Documents Data DTO
 * 
 * Represents document URLs in v2 API response
 */
class DocumentsData
{
    public function __construct(
        public ?string $pdf_url = null,
        public ?string $xml_url = null
    ) {}

    /**
     * Create from API response array
     */
    public static function fromArray(array $data): self
    {
        return new self(
            pdf_url: $data['pdf_url'] ?? null,
            xml_url: $data['xml_url'] ?? null
        );
    }

    /**
     * Validate documents data
     * 
     * @return array Empty array if valid, array of errors if invalid
     */
    public function validate(): array
    {
        $errors = [];

        // Validate URL formats if provided
        if ($this->pdf_url !== null && !filter_var($this->pdf_url, FILTER_VALIDATE_URL)) {
            $errors['pdf_url'] = 'Invalid PDF URL format';
        }

        if ($this->xml_url !== null && !filter_var($this->xml_url, FILTER_VALIDATE_URL)) {
            $errors['xml_url'] = 'Invalid XML URL format';
        }

        return $errors;
    }
}
