<?php

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


use App\Classes\Modules\Accounts\Exceptions\CannotCreateOrderStepsException;
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Models\Order;

class CreatesOrderSteps
{

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

    /**
     * CompletesOrderStep constructor.
     */
    public function __construct()
    {
        $this->repository = new Order();
    }

    /**
     * @param int $orderId
     * @param array $orderSteps
     * @throws CannotCreateOrderStepsException
     */
    public function execute(int $orderId, array $orderSteps){

        try {

            /** @var Order $repository */
            $repository = $this->repository->findOrFail($orderId);

            $repository->orderSteps()->delete();

            $repository->orderSteps()->createMany($orderSteps);

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



    }

}