class RCUtils {

    @SuppressWarnings("unchecked")
    public static void validateSettingsParms(HashMap<String, Object> parameters) throws RCException
    {
        validatePushSettings(parameters);
      /*
      if (parameters.containsKey(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED) &&
            ((Boolean)parameters.get(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED))) {
       */

        if (!parameters.containsKey(RCDevice.ParameterKeys.SIGNALING_USERNAME) ||
                parameters.get(RCDevice.ParameterKeys.SIGNALING_USERNAME).equals("")) {
            throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_USERNAME);
            //return new ErrorStruct(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_USERNAME);
        }

        if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE)) {
            // discovery type not provided
            parameters.put(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE, RCDevice.MediaIceServersDiscoveryType.ICE_SERVERS_CONFIGURATION_URL_XIRSYS_V2);
        }
        else {
            // discovery type provided
            RCDevice.MediaIceServersDiscoveryType iceServersDiscoveryType;
            if (parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE) instanceof Enum){
                iceServersDiscoveryType = (RCDevice.MediaIceServersDiscoveryType)parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE);
            } else {
                int discoveryType = (int)parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS_DISCOVERY_TYPE);
                if (discoveryType >= RCDevice.MediaIceServersDiscoveryType.values().length || discoveryType < 0){
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_INVALID_ICE_SERVER_DISCOVERY_TYPE);
                }else {
                    iceServersDiscoveryType = RCDevice.MediaIceServersDiscoveryType.values()[discoveryType];
                }
            }

            if (iceServersDiscoveryType == RCDevice.MediaIceServersDiscoveryType.ICE_SERVERS_CUSTOM) {
                // custom (i.e. no configuration url used)
                if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS) || parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS) == null ||
                        ((List<Map<String,String>>) parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS)).size() == 0) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_INVALID_CUSTOM_DISCOVERY_NO_ICE_SERVERS);
                }

                List<Map<String, String>> iceServers = (List<Map<String, String>>)parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS);
                for (Map<String, String> iceServer : iceServers) {
                    if (!iceServer.containsKey(RCConnection.IceServersKeys.ICE_SERVER_URL) ||
                            iceServer.get(RCConnection.IceServersKeys.ICE_SERVER_URL).equals("")) {
                        throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_INVALID_CUSTOM_DISCOVERY);
                    }
                }

                if (parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_URL) ||
                        parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME) ||
                        parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD) ||
                        parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN)) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_INVALID_CUSTOM_DISCOVERY);
                }
            }
            else {
                // not custom; media ice servers shouldn't be provided
                if (parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_SERVERS)) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_INVALID_ICE_SERVERS_NOT_CUSTOM_DISCOVERY);
                }

                // all those fields are mandatory when configuration URL is used
                if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_URL) ||
                        parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_URL).equals("")) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_ICE_URL);
                }
                if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME) ||
                        parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME).equals("")) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_ICE_USERNAME);
                }
                if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD) ||
                        parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD).equals("")) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_ICE_PASSWORD);
                }
                if (!parameters.containsKey(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN) ||
                        parameters.get(RCDevice.ParameterKeys.MEDIA_ICE_DOMAIN).equals("")) {
                    throw new RCException(RCClient.ErrorCodes.ERROR_DEVICE_MISSING_ICE_DOMAIN);
                }
            }
        }
    }

}