<?php

namespace App\Data\Pagarme\Order\Parts\Request;

use App\Data\Pagarme\PagarmeData;

final readonly class ItemData extends PagarmeData
{
    public function __construct(
        public string  $code,
        public int     $amount,
        public int     $quantity,
        public ?string $description = null,
    ) {
        self::requireFilled($this->code, 'items.code');
        self::requirePositiveInt($this->amount, 'items.amount');
        self::requirePositiveInt($this->quantity, 'items.quantity');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'code'        => $this->code,
            'amount'      => $this->amount,
            'quantity'    => $this->quantity,
            'description' => $this->description,
        ]);
    }
}
