<?php

namespace App\Data\Pagarme\Response\OrderResponseData\OrderChargeResponseData;

use App\Data\Pagarme\PagarmeResponseData;

final readonly class OrderTransactionResponseData extends PagarmeResponseData
{
    public function __construct(
        public ?string $id,
        public ?string $status,
        public ?int    $amount,
        public ?string $createdAt,
        public ?string $acquirerMessage,
        public array   $gatewayResponse,
    ) {}

    public static function fromArray(array $payload): static
    {
        return new self(
            id:              static::arrString($payload, 'id'),
            status:          static::arrString($payload, 'status'),
            amount:          static::arrInt($payload, 'amount'),
            createdAt:       static::arrString($payload, 'created_at'),
            acquirerMessage: static::arrString($payload, 'acquirer_message'),
            gatewayResponse: static::arrArray($payload, 'gateway_response'),
        );
    }

    public function toArray(): array
    {
        return [
            'id'               => $this->id,
            'status'           => $this->status,
            'amount'           => $this->amount,
            'created_at'       => $this->createdAt,
            'acquirer_message' => $this->acquirerMessage,
            'gateway_response' => $this->gatewayResponse,
        ];
    }
}
