<?php

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


use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Classes\Modules\Orders\DataTransferObjects\PackingListObject;
use App\Models\Order;
use App\Models\Package;
use App\Models\PackingList;

class UpdatesPackages
{

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

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


    public function execute(int $orderId, array $packages){
        /** @var Order $order */
        $order = Order::findOrFail($orderId);
        $order->packages()->delete();
        $order->packages()->createMany($packages);
    }

}