<?php
namespace Podeli\Payment\Methods;

use Podeli\Payment\Models\RefundOrder;

class Refund extends BaseMethod
{
    private ?RefundOrder $refundOrder = null;
    private ?string $orderId = null;

    const HTTP_METHOD = 'POST';

    const PATH = 'refund';

    public function getPath()
    {
        if (is_null($this->orderId)) {
            throw new \Exception('Empty order');
        }
        return sprintf('%s/%s', $this->orderId, static::PATH);
    }

    public function setOrderId(string $orderId)
    {
        $this->orderId = $orderId;
        return $this;
    }

    public function setRefundOrder(RefundOrder $order)
    {
        $this->refundOrder = $order;
        return $this;
    }

    public function getData()
    {
        if (is_null($this->refundOrder)) {
            throw new \Exception('Empty refund order');
        }
        $data = [
            'order' => [
                'refund' => $this->refundOrder->toArray()
            ]
        ];

        return $data;
    }
}
