<?php

namespace App\Classes\Modules\Steps\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Steppable;
use App\Classes\Modules\Steps\DataTransferObjects\StepsObject;
use App\Models\Step;
use App\Models\Order;

class CreatesStep extends AbstractUpdateRelationshipRecord
{

    /**
     * @param Steppable $owner
     * @param StepsObject $orderSteps
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Steppable $owner, StepsObject $orderSteps) {

        $model = new Step();

        $model->appointee_id = $orderSteps->getAppointeeId();
        $model->reference = $orderSteps->getReference();
        $model->sequence = $orderSteps->getSequence();
        $model->obligation_hash_id = $orderSteps->getObligationId();

        return $this->handler($owner->steps(), $model);

    }
}
