<?php

namespace CouponsPlus\App\Coupon\Tree\ItemSetsToDiscount;

use stdClass;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\Original\Collections\JSONMapper;
use CouponsPlus\Original\Collections\MappedObject;
use CouponsPlus\Original\Collections\Mapper\Types;
use CouponsPlus\App\Coupon\Tree\Abilities\ItemsInCartFinderStrategy;
use CouponsPlus\App\Coupon\Tree\ItemSetsToDiscount\Abilities\ProductsInCartFinderStrategyOptionalFactory;

class SpecificProductsInCartFinderStrategyFactory implements ProductsInCartFinderStrategyOptionalFactory
{
    public function canCreate(string $mode): bool
    {
        return $mode === 'products';
    }

    /**
     * @param Collection $data
     */
    public function create($data): ItemsInCartFinderStrategy
    {
        /**
         * Todo:
         */
        $productDiscountMapper = new JSONMapper([
            // youb know what let's map the product source here...
        ]);
        $actionsMapper = new JSONMapper([
            'notInCart' => [
                'features' => Types::STRING()->withDefault('auto_apply')->allowed([
                    'auto_apply',
                    'show_notification'
                ]),
                'show_notification' => [
                    'message' => Types::STRING(),
                    'button' => [
                        'text' => Types::STRING(),
                    ]
                ]
            ]
        ]);

        $data = $data->map(function (stdClass $data) use ($actionsMapper): stdClass {
            $data->actions = $actionsMapper->map($data->actions ?? '');
            return $data;
        });

        return new SpecificItemsInCartFinderStrategy($data);
    }
}