<?php

namespace App\Classes\Modules\Vouchers\Services;

use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
use App\Classes\General\Interfaces\Voucherifiable;
use App\Models\VoucherEntityMapping;

class CreatesVoucherEntityMapping extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Voucherifiable $voucherifable
     * @param VoucherObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Voucherifiable $voucherifable, VoucherEntityObject $object) {
        $model = new VoucherEntityMapping();
        $model->voucherify_entity_id = $object->getId();
        $model->voucherify_entity_type = $object->getType();
        return $this->handler($voucherifable->voucherifyEntities(), $model);
    }
}
