<?php
namespace Podeli\Payment\Methods;

use Podeli\Payment\Models\CommitOrder;

class Commit extends BaseMethod
{
    private ?CommitOrder $order = null;

    const HTTP_METHOD = 'POST';

    const PATH = 'commit';

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

    public function setOrder(CommitOrder $order)
    {
        $this->order = $order;
        return $this;
    }

    public function getData()
    {
        $data = [
            'order' => $this->order->toArray()
        ];

        return $data;
    }
}
