<?php

namespace CouponsPlus\App\Data\Store;

use WC_Coupon;
use CouponsPlus\App\Coupon\Rows;
use CouponsPlus\App\Export\DataExporter;
use CouponsPlus\Original\Environment\Env;

#[\AllowDynamicProperties]
Class CouponModelStorer extends PostStorer
{
    protected function getPostFieldName() : string
    {
        return Env::getWithPrefix('model');
    }

    protected function storeData()
    {
        (string) $model = $this->getData();

        if (!in_array($model, ['tree', 'rows', 'classic'])) {
            return;
        }

        // crucially, we have to update the coupon discount type too.
        if ($model === 'tree') {
            $this->updateMeta('discount_type', 'coupons+');
        }

        $this->updateMeta(
            $this->getPostFieldName(),
            $this->getData()
        );

    }
}
