<?php

namespace App\Classes\Modules\PackingLists\Processors;


use App\Classes\General\Interfaces\Packable;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;

class CreatePackingListProcessor
{


    /** @var CanCreatePackingList */
    private $canCreatePackingList;

    /** @var CreatesPackingList */
    private $createsPackingList;


    /**
     * CreatePackingListProcessor constructor.
     * @param CanCreatePackingList $canCreatePackingList
     * @param CreatesPackingList $createsPackingList
     */
    public function __construct(CanCreatePackingList $canCreatePackingList, CreatesPackingList $createsPackingList)
    {
        $this->canCreatePackingList = $canCreatePackingList;
        $this->createsPackingList = $createsPackingList;
    }

    /**
     * @param PackingListObject $object
     * @param Packable $packable
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function execute(PackingListObject $object, Packable $packable){

        $this->canCreatePackingList->passes($object);
        return $this->createsPackingList->execute($object, $packable);
    }

}