<?php

declare(strict_types=1);

namespace CloudXM\NFe\DTOs;

use JsonSerializable;

/**
 * Cancel Invoice Request DTO
 * 
 * Represents the v2 API request for cancelling an invoice
 */
class CancelInvoiceRequest implements JsonSerializable
{
    public function __construct(
        public string $justification
    ) {}

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

        if (empty($this->justification)) {
            $errors['justification'] = 'Justification is required';
        }

        if (strlen($this->justification) < 15) {
            $errors['justification'] = 'Justification must be at least 15 characters';
        }

        return $errors;
    }

    /**
     * Serialize to JSON for API request
     */
    public function jsonSerialize(): array
    {
        return [
            'justification' => $this->justification,
        ];
    }
}
