<?php

declare(strict_types=1);

namespace Paysera\CheckoutSdk\Service\Normalizer;

use Paysera\CheckoutSdk\Entity\RefundCallback;
use Paysera\CheckoutSdk\Entity\RefundStatus;
use Paysera\CheckoutSdk\Util\TypeConverter;

class RefundCallbackNormalizer
{
    private TypeConverter $typeConverter;

    public function __construct(
        TypeConverter $typeConverter
    ) {
        $this->typeConverter = $typeConverter;
    }

    public function denormalize(array $data): RefundCallback
    {
        return new RefundCallback(
            $this->typeConverter->convert($data['orderId'] ?? '', TypeConverter::STRING),
            $this->typeConverter->convert($data['reference'] ?? '', TypeConverter::STRING),
            new RefundStatus(
                $this->typeConverter->convert($data['status'] ?? '', TypeConverter::STRING)
            ),
            $this->typeConverter->convert($data['amount'] ?? 0, TypeConverter::INT),
            $this->typeConverter->convert($data['currency'] ?? '', TypeConverter::STRING),
            $this->typeConverter->convert($data['timestamp'] ?? 0, TypeConverter::INT)
        );
    }
}
