<?php

namespace App\Classes\Modules\Orders\Services;


use App\Classes\Modules\Accounts\Exceptions\CannotUpdateOrderWarehouseException;
use App\Models\OrderWarehouse;

class UpdatesOrderWarehouse
{

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

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


    /**
     * @param int $orderId
     * @param $warehouseId
     * @param $type
     * @throws CannotUpdateOrderWarehouseException
     */
    public function execute(int $orderId, $warehouseId, $type){
        try {
            $this->repository->updateOrCreate(['order_id' => $orderId, 'type' =>$type], ['warehouse_id' => $warehouseId]);

        } catch (\Exception $exception){
            throw new CannotUpdateOrderWarehouseException($exception->getMessage());
        }

    }

}