import 'ts-polyfill/lib/es2017-object';
import { Environment } from '../models/configuration/environment';
import { NonstopConfig } from '../models/configuration/nonstopConfig';
import { Platform } from '../models/configuration/platform';
import { BaseService } from './abstract/baseService';

class ConfigurationService extends BaseService {
    public static sharedInstance = new ConfigurationService();

    protected logTag: string = 'ConfigurationService';

    public validateConfiguration(config: NonstopConfig): boolean {
        if (!Object.values(Environment).includes(config.environment)) {
            this.logError('Invalid Environment passed to Nonstop.initialize. Execution will continue but behaviour may be undefined.');
            this.logError(`Valid values are ${Object.values(Environment).join(', ')}`);
            return false;
        }
        if (!Object.values(Platform).includes(config.platform)) {
            this.logError('Invalid Platform passed to Nonstop.initialize. Execution will continue but behaviour may be undefined.');
            this.logError(`Valid values are ${Object.values(Platform).join(', ')}`);
            return false;
        }
        return true;
    }
}

export default ConfigurationService.sharedInstance as ConfigurationService;