<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class RegisterInformationData extends PagarmeData
{
    public function __construct(
        public string  $name,
        public string  $email,
        public string  $document,
        public string  $type,
        public ?string $birthdate,
        public int     $monthlyIncome,
        public string  $professionalOccupation,

        public PhoneNumbersData $phoneNumbers,
        public AddressData      $address,
    ) {
        self::requireFilled($this->name, 'register_information.name');
        self::requireFilled($this->email, 'register_information.email');
        self::requireFilled($this->document, 'register_information.document');
        self::requireIn($this->type, ['individual', 'corporation', 'company'], 'register_information.type');
        self::requirePositiveInt($this->monthlyIncome, 'register_information.monthly_income');
        self::requireFilled($this->professionalOccupation, 'register_information.professional_occupation');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'name'                    => $this->name,
            'email'                   => $this->email,
            'document'                => $this->document,
            'type'                    => $this->type,
            'birthdate'               => $this->birthdate,
            'monthly_income'          => $this->monthlyIncome,
            'professional_occupation' => $this->professionalOccupation,
            'phone_numbers'           => $this->phoneNumbers,
            'address'                 => $this->address,
        ]);
    }
}
