<?php

namespace App\Classes\Modules\PackingLists\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Packable;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Models\PackingList;

class CreatesPackingList extends AbstractUpdateRelationshipRecord
{
    /**
     * @param PackingListObject $object
     * @param Packable $packable
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(PackingListObject $object, Packable $packable) {
        $model = new PackingList();

        $model->reference = $object->getReference();
        $model->claimant_id = $object->getClaimantId();
        $model->type = $object->getType();
        $model->status = $object->getStatus();
        $model->reference_contract = $object->getContractReference();

        return $this->handler($packable->packingLists(), $model);
    }
}
