<?php

namespace CouponsPlus\App\Coupon\Tree\Factories;

use CouponsPlus\App\Coupon\Tree\Abilities\FilterableGroup;
use CouponsPlus\App\Coupon\Tree\ORInclusiveTestableGroup;
use CouponsPlus\App\Coupon\Tree\ANDTestableGroup;
use CouponsPlus\App\Coupon\Tree\ORTestableGroup;
use CouponsPlus\App\Coupon\Tree\Abilities\TestableGroupData;

class FilterableGroupFactory implements FilterableGroupFactoryInterface
{
    /**
     * Should probably be extracted to they own classes. But whatever
     * @param string $type
     * @param $testableGroupData
     */
    public function create(string $type, $testableGroupData) : FilterableGroup
    {
        switch ($type) {
            case 'OR':
            case 'OR_INCLUSIVE':
                $testableGroup = new ORInclusiveTestableGroup;
                break;
            case 'OR_EXCLUSIVE':
                $testableGroup = new ORTestableGroup;
                break;
            case 'AND':
            default:
            $testableGroup = new ANDTestableGroup;
                break;
        }

        if (!$testableGroupData->canFilterItems()) {
            $testableGroup->canRecordSource = false;
        }

        return $testableGroup;
    }
}