<?php

namespace App\Classes\Modules\Companies\Services;


use App\Classes\Modules\Companies\Exceptions\CannotListCompanyOrderCategoryException;
use App\Models\Order;
use App\Http\Resources\Order as OrderResource;

class ListsCompanyOrdersCategory
{

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

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

    public function execute(int $id, array $category){

        try {
            /** @var Order $orders */
            $orders = $this->repository->where('company_id', $id)
                ->whereIn('current_step', $category)->orderBy('created_at', 'desc')->get();

            return OrderResource::collection($orders);
        } catch (\Exception $exception){
            throw new CannotListCompanyOrderCategoryException($exception->getMessage());
        }


    }

}