<?php

namespace App\Classes\Modules\PackingLists\Processors;


use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerObject;
use App\Classes\Modules\PackingLists\Services\Containers\CreatesContainer;
use App\Classes\Modules\PackingLists\Standards\Rules\Containers\CanCreateContainer;

class CreateContainerProcessor
{
    /** @var CanCreateContainer */
    private $canCreateContainer;

    /** @var CreatesContainer */
    private $createsContainer;

    /**
     * CreateContainerProcessor constructor.
     * @param CanCreateContainer $canCreateContainer
     * @param CreatesContainer $createsContainer
     */
    public function __construct(CanCreateContainer $canCreateContainer, CreatesContainer $createsContainer)
    {
        $this->canCreateContainer = $canCreateContainer;
        $this->createsContainer = $createsContainer;
    }


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

        $this->canCreateContainer->passes($object);
        return $this->createsContainer->execute($object, $owner);
    }

}