<?php

namespace CouponsPlus\App\Coupon\Tree\Finders;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeData;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeFinder;

class OverloadableNodeFinder implements NodeFinder
{
    private $factoryoverloader;

    public function __construct($factoryoverloader)
    {
        $this->factoryoverloader = $factoryoverloader;
    } 

    public function find(ItemsSet $itemsSet, NodeDatasWithBranch $nodeDatasWithBranch): NodeData
    {
        (object) $branch = $nodeDatasWithBranch->getBranch();

        /** @var NodeFinder */
        (object) $findableOffersFromBranch = $this->factoryoverloader->overload($branch);

        return $findableOffersFromBranch->find($itemsSet, $nodeDatasWithBranch);
    } 
}