<?php

namespace App\Classes\Modules\PackingLists\Services\Containers;

use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Models\Container;

class CreatesContainer extends AbstractUpdateRelationshipRecord
{

    /**
     * @param ContainerObject $object
     * @param ContainerOwner $owner
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(ContainerObject $object, ContainerOwner $owner) {
        $model = new Container();

        $model->reference = $object->getReference();
        $model->container_number = $object->getContainerNumber();
        $model->container_type = $object->getContainerType();
        $model->seal_reference = $object->getSealReference();
        $model->loading_date = $object->getLoadingDate();
        $model->status = $object->getStatus();

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