<?php

namespace App\Data\Pagarme\Customer;

use App\Data\Pagarme\PagarmeData;
use App\Data\Pagarme\Customer\Parts\Request\AddressData;
use App\Data\Pagarme\Customer\Parts\Request\PhonesData;

final readonly class CustomerRequestData extends PagarmeData
{
    public function __construct(
        public string $name,
        public string $email,
        public string $document,
        public string $type,
        public string $documentType,
        public string $code,

        public ?AddressData $address = null,
        public ?PhonesData  $phones  = null,
    ) {
        self::requireFilled($this->name, 'name');
        self::requireFilled($this->email, 'email');
        self::requireFilled($this->document, 'document');
        self::requireIn($this->type, ['individual', 'company'], 'type');
        self::requireIn($this->documentType, ['CPF', 'CNPJ', 'PASSPORT'], 'document_type');
        self::requireFilled($this->code, 'code');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'name'          => $this->name,
            'email'         => $this->email,
            'document'      => $this->document,
            'type'          => $this->type,
            'document_type' => $this->documentType,
            'code'          => $this->code,
            'address'       => $this->address,
            'phones'        => $this->phones,
        ]);
    }
}
