<?php

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

use App\Data\Pagarme\PagarmeData;

final readonly class AddressData extends PagarmeData
{
    public function __construct(
        public string  $street,
        public string  $complementary,
        public string  $streetNumber,
        public string  $neighborhood,
        public ?string $city,
        public ?string $state,
        public string  $zipCode,
        public string  $referencePoint,
    ) {
        self::requireFilled($this->street, 'register_information.address.street');
        self::requireFilled($this->streetNumber, 'register_information.address.street_number');
        self::requireFilled($this->neighborhood, 'register_information.address.neighborhood');
        self::requireFilled($this->city, 'register_information.address.city');
        self::requireFilled($this->state, 'register_information.address.state');
        self::requireFilled($this->zipCode, 'register_information.address.zip_code');
    }

    public function toArray(): array
    {
        return $this->filterFilledRecursive([
            'street'          => $this->street,
            'complementary'   => $this->complementary,
            'street_number'   => $this->streetNumber,
            'neighborhood'    => $this->neighborhood,
            'city'            => $this->city,
            'state'           => $this->state,
            'zip_code'        => $this->zipCode,
            'reference_point' => $this->referencePoint,
        ]);
    }
}
