AutomaticAnticipationSettingsData.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Data\Pagarme\Recipient\Parts\Request;
  3. use App\Data\Pagarme\PagarmeData;
  4. final readonly class AutomaticAnticipationSettingsData extends PagarmeData
  5. {
  6. public function __construct(
  7. public bool $enabled,
  8. public ?string $type = null,
  9. public ?int $volumePercentage = null,
  10. public ?int $delay = null,
  11. public ?array $days = null,
  12. ) {
  13. if ($this->type !== null) {
  14. self::requireIn($this->type, ['full', '1025'], 'automatic_anticipation_settings.type');
  15. }
  16. if ($this->volumePercentage !== null && ($this->volumePercentage < 0 || $this->volumePercentage > 100)) {
  17. throw new \InvalidArgumentException('automatic_anticipation_settings.volume_percentage deve estar entre 0 e 100.');
  18. }
  19. if ($this->delay !== null && $this->delay < 0) {
  20. throw new \InvalidArgumentException('automatic_anticipation_settings.delay deve ser maior ou igual a zero.');
  21. }
  22. }
  23. public function toArray(): array
  24. {
  25. return $this->filterFilledRecursive([
  26. 'enabled' => $this->enabled,
  27. 'type' => $this->type,
  28. 'volume_percentage' => $this->volumePercentage,
  29. 'delay' => $this->delay,
  30. 'days' => $this->days,
  31. ]);
  32. }
  33. }