<?php

namespace App\Classes\Modules\PackingLists\Processors;


use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Classes\Modules\PackingLists\Services\Packages\CreatesPackage;
use App\Classes\Modules\PackingLists\Standards\Rules\Packages\CanCreatePackage;
use App\Models\PackingList;

class CreatePackageProcessor
{


    /** @var CanCreatePackage */
    private $canCreatePackage;

    /** @var CreatesPackage */
    private $createsPackage;

    /**
     * CreatePackageProcessor constructor.
     * @param CanCreatePackage $canCreatePackage
     * @param CreatesPackage $createsPackage
     */
    public function __construct(CanCreatePackage $canCreatePackage, CreatesPackage $createsPackage)
    {
        $this->canCreatePackage = $canCreatePackage;
        $this->createsPackage = $createsPackage;
    }


    /**
     * @param PackageObject $object
     * @param PackingList $packingList
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function execute(PackageObject $object, PackingList $packingList){

        $this->canCreatePackage->passes($object);

        return $this->createsPackage->execute($object, $packingList);

    }

}