package cz.moneta.test.harness.endpoints.smartbanka;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.exception.HarnessException;

import java.util.Arrays;

public enum MobilePlatform {
    IOS("ios"),
    ANDROID("android"),
    IOS_SIMULATOR("ios simulator");

    private final String mobilePlatform;

    MobilePlatform(String mobilePlatform) {
        this.mobilePlatform = mobilePlatform;
    }

    public String getMobilePlatform() {
        return mobilePlatform;
    }

    public static MobilePlatform getMobilePlatformFromConfig(StoreAccessor store, String configKey) {
        return Arrays.stream(values())
                .filter(mobile -> mobile.getMobilePlatform().equalsIgnoreCase(store.getConfig(configKey)))
                .findFirst()
                .orElseThrow(() -> new HarnessException("You need to define " + configKey + " in config file for working with mobile devices"));
    }

    public static MobilePlatform getMobilePlatformFromConfig(StoreAccessor store) {
        return getMobilePlatformFromConfig(store, "mobile.platform");
    }

    public static Boolean isAndroid(StoreAccessor store) {
        return getMobilePlatformFromConfig(store).equals(MobilePlatform.ANDROID);
    }
}
