<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class TransferSettingsData extends PagarmeData
{
    public function __construct(
        public bool   $transferEnabled,
        public string $transferInterval,
        public int    $transferDay,
    ) {
        self::requireIn($this->transferInterval, ['Daily', 'Weekly', 'Monthly'], 'transfer_interval');

        if ($this->transferDay < 0) {
            throw new \InvalidArgumentException('transfer_day deve ser maior ou igual a zero.');
        }
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'transfer_enabled'  => $this->transferEnabled,
            'transfer_interval' => $this->transferInterval,
            'transfer_day'      => $this->transferDay,
        ]);
    }
}
