<?php

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

use App\Data\Pagarme\PagarmeResponseData;

final readonly class ItemData extends PagarmeResponseData
{
    public function __construct(
        public ?string $id,
        public ?string $code,
        public ?int    $amount,
        public ?int    $quantity,
        public ?string $description,
        public ?string $status,
    ) {}

    public static function fromArray(array $payload): static
    {
        return new self(
            id:          static::arrString($payload, 'id'),
            code:        static::arrString($payload, 'code'),
            amount:      static::arrInt($payload, 'amount'),
            quantity:    static::arrInt($payload, 'quantity'),
            description: static::arrString($payload, 'description'),
            status:      static::arrString($payload, 'status'),
        );
    }

    public function toArray(): array
    {
        return [
            'id'          => $this->id,
            'code'        => $this->code,
            'amount'      => $this->amount,
            'quantity'    => $this->quantity,
            'description' => $this->description,
            'status'      => $this->status,
        ];
    }
}
