<?php

namespace App\Data\Pagarme\Recipient;

use App\Data\Pagarme\PagarmeData;

final readonly class BankAccountUpdateRequestData 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, 'bank_account.holder_name');
        self::requireIn($this->holderType, ['individual', 'company'], 'bank_account.holder_type');
        self::requireFilled($this->holderDocument, 'bank_account.holder_document');
        self::requireFilled($this->bank, 'bank_account.bank');
        self::requireFilled($this->branchNumber, 'bank_account.branch_number');
        self::requireFilled($this->accountNumber, 'bank_account.account_number');
        self::requireFilled($this->accountCheckDigit, 'bank_account.account_check_digit');
        self::requireFilled($this->type, 'bank_account.type');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'bank_account' => [
                '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,
            ],
        ]);
    }
}
