import {ComponentExporterImporter, PreloadedDynamicValues} from "../ComponentExporterImporter";
import {TestableData} from "../../store";
import {ProductsOptions} from "../../cards/Products";
import {ExportImportTarget} from "../Exporters";
import {merge} from "lodash";

export class ProductsExporterImporter implements ComponentExporterImporter<TestableData<ProductsOptions>, TestableData<ProductsOptions>> {
    type= 'Products';
    exportData(data: TestableData<ProductsOptions>, target: ExportImportTarget): TestableData<ProductsOptions> {
        if (target === 'preset') {
            // make sure the ids are empty for presets!
            data.options.ids = []
        }
        /**
         * Make sure the mode is always 'short' cause that's what we currently only support and default is 'classic' for bc so we have to explicitly set it here.
         */
        return merge(data, {
            options: {
                mode: 'short'
            }
        } as TestableData<ProductsOptions>)
    }

    tagDynamicValues({options: {ids}}: TestableData<ProductsOptions>, target: ExportImportTarget): PreloadedDynamicValues {
        return {
            category: 'products',
            values: ids
        };
    }
}