import { useMainStore } from '@/store';

export default {
    methods: {
        hasSettingEqualTo(settingName, settingValue) {
            return useMainStore().experimentSettings[settingName] === settingValue;
        },
        hasSetting(settingName) {
            return Object.hasOwn(useMainStore().experimentSettings, settingName);
        },
        getExperimentByName(experimentName) {
            const experiment = useMainStore().applicationUser.experiments.find((e) => e.universeName === experimentName);
            return experiment ? experiment : null;
        },
        getExperimentByTestName(testName) {
            const experiment = useMainStore().applicationUser.experiments.find((experiment) => experiment.testName === testName);
            return experiment ? experiment : null;
        },
        getExperimentVariationNameByTestName(testName) {
            const experimentByTestName = this.getExperimentByTestName(testName);
            if (!experimentByTestName) {
                return null;
            }
            return experimentByTestName.variationName;
        },
        getSettingValue(settingName) {
            return this.hasSetting(settingName)
                ? useMainStore().experimentSettings[settingName]
                : null;
        }
    }
};
