<?php

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

use App\Data\Pagarme\PagarmeResponseData;

final readonly class AddressData extends PagarmeResponseData
{
    public function __construct(
        public ?string $id,
        public ?string $line1,
        public ?string $line2,
        public ?string $zipCode,
        public ?string $city,
        public ?string $state,
        public ?string $country,
        public ?string $status,
        public ?string $createdAt = null,
        public ?string $updatedAt = null,
    ) {}

    public static function fromArray(array $payload): static
    {
        return new self(
            id:        static::arrString($payload, 'id'),
            line1:     static::arrString($payload, 'line_1'),
            line2:     static::arrString($payload, 'line_2'),
            zipCode:   static::arrString($payload, 'zip_code'),
            city:      static::arrString($payload, 'city'),
            state:     static::arrString($payload, 'state'),
            country:   static::arrString($payload, 'country'),
            status:    static::arrString($payload, 'status'),
            createdAt: static::arrString($payload, 'created_at'),
            updatedAt: static::arrString($payload, 'updated_at'),
        );
    }

    public function toArray(): array
    {
        return [
            'id'         => $this->id,
            'line_1'     => $this->line1,
            'line_2'     => $this->line2,
            'zip_code'   => $this->zipCode,
            'city'       => $this->city,
            'state'      => $this->state,
            'country'    => $this->country,
            'status'     => $this->status,
            'created_at' => $this->createdAt,
            'updated_at' => $this->updatedAt,
        ];
    }
}
