<?php

namespace CouponsPlus\App\Coupon\Tree\Sets\Factories;

use CouponsPlus\App\Coupon\Tree\Sets\ItemsSetSorter;
use CouponsPlus\App\Coupon\Tree\Sets\NoSpecialSorting;
use CouponsPlus\App\Coupon\Tree\Sets\ActivePriceStrategy;
use CouponsPlus\App\Coupon\Tree\Sets\AscendingItemsSorter;
use CouponsPlus\App\Coupon\Tree\Sets\DescendingItemsSorter;
use CouponsPlus\App\Coupon\Tree\Sets\Abilities\ItemsSetSorterInterface;

class PriceSorterFactory
{
    public const NONE = 'none';
    public const CHEAPEST = 'cheap';
    public const MOST_EXPENSIVE = 'expensive';

    /**
     * todo: in the future we might have options here, like the type of strategy to use (active price, regular price, line item price, etc)
     */
    public function __construct()
    {
    }

    /**
     * @param static::CHEAPEST|static::MOST_EXPENSIVE $option
     */
    public function create(string $option) : ItemsSetSorterInterface
    {
        $activePriceSorter = new ItemsSetSorter(
            /*
             * This strategy is bound to change in the future depending on whether we need to sort by active price, regular price, etc.
             */
            new ActivePriceStrategy
        );

        switch ($option) {
            case static::NONE:
                return new NoSpecialSorting();
            case static::CHEAPEST:
                return new AscendingItemsSorter($activePriceSorter);
            case static::MOST_EXPENSIVE:
                return new DescendingItemsSorter($activePriceSorter);
        }
    }
}