import {TestablePartial} from "./store";
import {increase} from "./tiers";
import {getCardRendererFromType} from "./cards";
import {getComponentMetaData, getComponentMetaFromType} from "./ComponentsMeta";
import {cloneDeep} from "lodash";

export const increaseNumericTestable = (testable: TestablePartial, type?: string) => {
    // THE TYPE IS 'CartSubtotal', 'IndividualItemPrice', etc.

    // for now let's just increase it assuming the options are under 'quantity'
    increase(testable.options.quantity)

    return testable
}

export const removeFixedTestableValues = (testable: TestablePartial, type: string) => {
    const cardRenderer = getCardRendererFromType(type)
    const meta = getComponentMetaFromType(type)

    if (cardRenderer && cardRenderer.removeFixedValues) {
        cardRenderer.removeFixedValues(testable.options)
    } else {
        if (meta) {
            testable.options = cloneDeep(getComponentMetaData(meta).defaultOptions) || {}
        } else {
            testable.options = {}
        }
    }
}