<?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\Offers\OffersSetCollection;
use Throwable;

class EmptyOffersOnErrorFinderFromBranch extends FindableOffersFromBranchComposite implements FindableOffersFromBranch
{
    public function findOffers(ItemsSet $itemsSet, Branch $branch): CartComponentsSet
    {
        try {
            (object) $offers = $this->findableOffersFromBranch->findOffers(...func_get_args());            
        } catch (Throwable $e) {
            (object) $offers = new OffersDataSet();
        }

        return $offers;
    } 
}