package cz.moneta.test.harness.endpoints;

import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.constants.HarnessConfigConstants;
import cz.moneta.test.harness.context.StoreAccessor;

public class CommonEndpoint implements Endpoint {

    private Environment environment;

    public CommonEndpoint(StoreAccessor storeAccessor) {
        this.environment = getEnvironmentByConfigName(storeAccessor);
    }

    private Environment getEnvironmentByConfigName(StoreAccessor storeAccessor) {
        String environmentConfigName = System.getProperty(HarnessConfigConstants.ENVIRONMENT_TYPE);

        if (environmentConfigName == null) {
            environmentConfigName = storeAccessor.getConfig(HarnessConfigConstants.ENVIRONMENT_TYPE);
        }

        return Environment.fromString(environmentConfigName);
    }

    public Environment getEnvironment() {
        return environment;
    }
}
