<?php

namespace CouponsPlus\App\Coupon\Tree\Finders;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\Branch;
use CouponsPlus\App\Coupon\CartComponentsSet;
use CouponsPlus\App\Coupon\Tree\Abilities\FindableOffersFromBranch;
use CouponsPlus\App\Coupon\Tree\Finders\Sets\OffersDataSet;
use CouponsPlus\App\Factory\Abilities\OverloadableFactory;

class EmptyOffersOnEmptyItemsSetOffersFinderFromBranch extends FindableOffersFromBranchComposite implements FindableOffersFromBranch, OverloadableFactory
{
    /** @param Branch $value */
    public function canCreate($value): bool
    {
        return $this->findableOffersFromBranch->canCreate($value);            
    } 

    public function findOffers(ItemsSet $itemsSet, Branch $branch): CartComponentsSet
    {
        if ($itemsSet->getItems()->haveNone()) {
            return new OffersDataSet([]);
        }

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