import remoteConfig from "@react-native-firebase/remote-config";
import config, { FETCH_INTERVAL } from "./FirebaseRemoteConfig.config";

// set defaults
remoteConfig().setDefaults(config);

// fetch remote config
export const getConfig = () => {
  // data is locally cached for FETCH_INTERVAL
  const fetchConfig = remoteConfig().fetch(FETCH_INTERVAL);
  return fetchConfig
    .then(() => remoteConfig().activate())
    .then(() => {
      return remoteConfig().getAll();
    })
    .then((fConfig) => {
      console.log("*** FirebaseConfig getConfig fConfig ", fConfig);
      return {
        ml_pose: fConfig.ml_pose.asBoolean(),
        ml_confidence: fConfig.ml_confidence.asNumber(),
        ml_OS_version: fConfig.ml_OS_version.asNumber(),
        ml_RAM: fConfig.ml_RAM.asNumber(), // RAM in MB
      };
    })
    .catch((error) => console.log(error));
};
// export const getConfig = () => {
//   return {
//     ml_pose: false,
//     ml_confidence: 0.8,
//   };
// };

export default getConfig;
