<?php

namespace App\Classes\Modules\Companies\Processors;

use App\Classes\Modules\Companies\Services\AssignsEmployee;
use App\Classes\Modules\Companies\Standards\Rules\CanAssignEmployee;
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
use Illuminate\Database\Eloquent\Model;

class AssignEmployeeProcessor
{

    /** @var CanAssignEmployee */
    private $canAssignEmployee;

    /** @var AssignsEmployee */
    private $assignsEmployee;

    /**
     * AssignEmployeeProcessor constructor.
     * @param CanAssignEmployee $canAssignEmployee
     * @param AssignsEmployee $assignsEmployee
     */
    public function __construct(CanAssignEmployee $canAssignEmployee, AssignsEmployee $assignsEmployee)
    {
        $this->canAssignEmployee = $canAssignEmployee;
        $this->assignsEmployee = $assignsEmployee;
    }

    /**
     * @param EmploymentObject $object
     * @return Model
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function execute(EmploymentObject $object): Model {

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

        return $this->assignsEmployee->execute($object);
    }

}