<?php

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

use App\Data\Pagarme\PagarmeResponseData;

final readonly class BankAccountData extends PagarmeResponseData
{
    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,
    ) {}

    public static function fromArray(array $payload): static
    {
        return new self(
            holderName:        static::arrString($payload, 'holder_name'),
            holderType:        static::arrString($payload, 'holder_type'),
            holderDocument:    static::arrString($payload, 'holder_document'),
            bank:              static::arrString($payload, 'bank'),
            branchNumber:      static::arrString($payload, 'branch_number'),
            branchCheckDigit:  static::arrString($payload, 'branch_check_digit'),
            accountNumber:     static::arrString($payload, 'account_number'),
            accountCheckDigit: static::arrString($payload, 'account_check_digit'),
            type:              static::arrString($payload, 'type'),
        );
    }

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