<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class CreditCardData extends PagarmeData
{
    public function __construct(
        public string  $cardId,
        public ?int    $installments        = null,
        public ?string $statementDescriptor = null,
        public ?string $operationType       = null,
    ) {
        self::requireFilled($this->cardId, 'credit_card.card_id');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'card_id'              => $this->cardId,
            'installments'         => $this->installments,
            'statement_descriptor' => $this->statementDescriptor,
            'operation_type'       => $this->operationType,
        ]);
    }
}
