<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class SplitData extends PagarmeData
{
    public function __construct(
        public int    $amount,
        public string $recipientId,
        public string $type = 'flat',

        public ?SplitOptionsData $options = null,
    ) {
        self::requirePositiveInt($this->amount, 'split.amount');
        self::requireFilled($this->recipientId, 'split.recipient_id');
        self::requireFilled($this->type, 'split.type');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'amount'       => $this->amount,
            'recipient_id' => $this->recipientId,
            'type'         => $this->type,
            'options'      => $this->options,
        ]);
    }
}
