<?php

namespace App\Classes\Modules\Transports\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Transportable;
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
use App\Models\Transport;
use App\Models\Container;

class CreatesTransport extends AbstractUpdateRelationshipRecord
{

    /**
     * @param TransportObject $object
     * @param Transportable $transportable
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(TransportObject $object, Transportable $transportable) {
        $model = new Transport();

        $model->type = $object->getType();
        $model->courier = $object->getCourier();
        $model->tracking_number = $object->getTrackingNumber();
        $model->dispatch_date = $object->getDispatchDate();
        $model->drop_date = $object->getDropDate();
        $model->status = $object->getStatus();

        return $this->handler($transportable->transports(), $model);

    }
}
