<?php

namespace CouponsPlus\App\Coupon\Meta;

use CouponsPlus\App\Coupon\ColumnsRegistrator;
use CouponsPlus\App\Coupon\Columns\SimpleColumn;
use CouponsPlus\App\Coupon\Meta\CouponComponentMeta;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\Original\Collections\Mapper\Types;

#[\AllowDynamicProperties]
Abstract Class ColumnMeta extends CouponComponentMeta
{
    abstract public function getName() : string;
    abstract public function getDescription() : string;
    abstract public function useOneOffersSetForAllContexts() : bool;
    abstract public function isOffersColumn() : bool;
    abstract public function getPreferredColumnConversion() : string;

    public static function getDefaultOptions() : Collection
    {
        return Collection::create([
            'testableType' => Types::STRING()->withDefault('conditions')
                                             ->allowed(['conditions', 'filters']),
            'type' => Types::STRING()->withDefault(SimpleColumn::TYPE)
                                     ->allowed(ColumnsRegistrator::get()->all()->map(function(string $Column) : string {
                                        return $Column::TYPE;
                                     })->asArray()),
            'defaultOffers' => Types::COLLECTION,
            'contexts' => Types::COLLECTION,
            /**
             * Please NOTE:
             *
             * By default it is 'top-to-bottom' for backwards compatibility, to prevent the current coupons
             * to break. In reality, however, the default is now 'bottom-to-top' and this is set in the dashboard
             * when creating *NEW* coupons.
             */
            'executionOrderMode' => Types::STRING()->withDefault('top-to-bottom')
                                                   ->allowed([
                                                        __('Legacy (top to bottom)', 'coupons-plus-for-woocommerce') => ColumnExecutionMode::TOP_TO_BOTTOM,
                                                        __('Natural', 'coupons-plus-for-woocommerce') => ColumnExecutionMode::BOTTOM_TO_TOP
                                                   ])
        ]);
    }

    public function getOptions() : Collection
    {
        return static::getDefaultOptions();
    }
}