<?php

namespace App\Classes\Modules\Orders\Services\Attachments;


use App\Classes\Modules\Orders\DataTransferObjects\DeliveryArrangementObject;
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Models\DeliveryArrangement;

class UpdatesDeliveryArrangement
{

    /** @var DeliveryArrangement */
    private $repository;

    /**
     * UpdatesDeliveryArrangement constructor.
     * @param DeliveryArrangement $repository
     */
    public function __construct(DeliveryArrangement $repository)
    {
        $this->repository = $repository;
    }


    /**
     * @param int $orderId
     * @param DeliveryArrangementObject $arrangement
     * @return mixed
     */
    public function execute(int $orderId, DeliveryArrangementObject $arrangement){
        $arrangement = $this->repository->updateOrCreate(['order_id' => $orderId],
            ['type' => $arrangement->getType(), 'vehicle_no' => $arrangement->getVehicleNumber()]);

        return $arrangement->id;
    }


}