<?php

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


use Illuminate\Support\Facades\Log;

class CreatesVoucherifyVoucherInACampaign
{

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


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

     /**
     * @param string $campaignName
     * @param string $code
     * @return null|object
     * @throws \Voucherify\ClientException
     */
    public function execute(string $campaignName, string $code)
    {
        try {
            $result = $this->voucherifyClient->campaigns->addVoucherWithCode($campaignName, $code);
            return $result;
        } catch (\Voucherify\ClientException $e) {
            Log::error('CreatesVoucherifyVoucherInACampaign '.$e);
            return null;
        }
    }
}
