<?php

namespace App\Classes\Modules\Vouchers\Services\Voucherify;

use Illuminate\Support\Facades\Log;
use App\Classes\Modules\Vouchers\DataTransferObjects\UpdateVoucherifyOrderObject;

class UpdatesVoucherifyOrder
{

    /** @var VoucherifyClient */
    private $voucherifyClient;


    /**
     * UpdatesVoucherifyOrder constructor.
     *
     */
    public function __construct()
    {
        $this->voucherifyClient = createVoucherifyClient();
    }


    /**
     * @param UpdateVoucherifyOrderObject $obj
     * @return null|object
     * @throws \Voucherify\ClientException
     */
    public function execute(UpdateVoucherifyOrderObject $obj)
    {
        try {
            $result = $this->voucherifyClient->orders->update([
                "id" => $obj->getId(),
                "status" => $obj->getStatus(),
            ]);
            return $result;
        } catch (\Voucherify\ClientException $e) {
            Log::error($e);
            return null;
        }
    }
}
