<?php

namespace App\Classes\Modules\Vouchers\Services;

use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Models\Transaction;
use App\Models\Voucher;
use App\Models\VoucherRedemption;

class CreatesVoucherRedemption extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Transaction $transaction
     * @param Voucher $voucher
     * @param string $redemptionId
     * @param float $value
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Transaction $transaction, Voucher $voucher, string $redemptionId, float $value) {
        $model = new VoucherRedemption();
        $model->voucher_id = $voucher->id;
        $model->redemption_id = $redemptionId;
        $model->value = $value;

        return $this->handler($transaction->voucherRedemption(), $model);
    }
}
