<?php

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

use App\Data\Pagarme\PagarmeResponseData;

final readonly class PhoneData extends PagarmeResponseData
{
    public function __construct(
        public ?string $countryCode,
        public ?string $areaCode,
        public ?string $number,
    ) {}

    public static function fromArray(array $payload): static
    {
        return new self(
            countryCode: static::arrString($payload, 'country_code'),
            areaCode:    static::arrString($payload, 'area_code'),
            number:      static::arrString($payload, 'number'),
        );
    }

    public function toArray(): array
    {
        return [
            'country_code' => $this->countryCode,
            'area_code'    => $this->areaCode,
            'number'       => $this->number,
        ];
    }
}
