<?php

namespace CouponsPlus\App\Coupon\Tree\Finders;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\App\Coupon\CartComponentsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\Branch;
use CouponsPlus\App\Coupon\Tree\Abilities\FindableOffersFromBranch;
use CouponsPlus\App\Factory\FactoryOverloader;

// variations:
// 1 - leaves (offers)
// 2 - nodes 
//    -1 tiered (numeric filters)
//    -2 or (condition and filter combinations)
// 
class RuntimeOffersFinderFromBranch implements FindableOffersFromBranch
{
    protected $findableOffersFromBranchFactoryOverloader;
    
    public function __construct(
        FactoryOverloader $findableOffersFromBranchFactoryOverloader
    ) {
        $this->findableOffersFromBranchFactoryOverloader = $findableOffersFromBranchFactoryOverloader;
    }
    
    public function findOffers(ItemsSet $itemsSet, Branch $branch): CartComponentsSet
    {
        (object) $findableOffersFromBranch = $this->findableOffersFromBranchFactoryOverloader->overload($branch);

        /** @var FindableOffersFromBranch */
        //        (object) $findableOffersFromBranch = $findableOffersFromBranchFactory->create($branch);

        return $findableOffersFromBranch->findOffers($itemsSet, $branch);
    }
}