<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class BankAccountData extends PagarmeData
{
    public function __construct(
        public string  $holderName,
        public string  $holderType,
        public string  $holderDocument,
        public string  $bank,
        public string  $branchNumber,
        public ?string $branchCheckDigit,
        public string  $accountNumber,
        public string  $accountCheckDigit,
        public string  $type,
    ) {
        self::requireFilled($this->holderName, 'holder_name');
        self::requireIn($this->holderType, ['individual', 'company'], 'holder_type');
        self::requireFilled($this->holderDocument, 'holder_document');
        self::requireFilled($this->bank, 'bank');
        self::requireFilled($this->branchNumber, 'branch_number');
        self::requireFilled($this->accountNumber, 'account_number');
        self::requireFilled($this->accountCheckDigit, 'account_check_digit');
        self::requireFilled($this->type, 'type');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'holder_name'          => $this->holderName,
            'holder_type'          => $this->holderType,
            'holder_document'      => $this->holderDocument,
            'bank'                 => $this->bank,
            'branch_number'        => $this->branchNumber,
            'branch_check_digit'   => $this->branchCheckDigit,
            'account_number'       => $this->accountNumber,
            'account_check_digit'  => $this->accountCheckDigit,
            'type'                 => $this->type,
        ]);
    }
}
