<?php

namespace App\Classes\Modules\Milestones\Processors;

use App\Classes\Modules\Milestones\Services\AssignsReward;
use App\Classes\Modules\Milestones\Standards\Rules\CanAssignReward;
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
use Illuminate\Database\Eloquent\Model;

class AssignRewardProcessor
{

    /** @var CanAssignReward */
    private $canAssignReward;

    /** @var AssignsReward */
    private $assignsReward;

    /**
     * AssignRewardProcessor constructor.
     * @param CanAssignReward $canAssignReward
     * @param AssignsReward $assignsReward
     */
    public function __construct(CanAssignReward $canAssignReward, AssignsReward $assignsReward)
    {
        $this->canAssignReward = $canAssignReward;
        $this->assignsReward = $assignsReward;
    }

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

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

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

}
