// Path: app/src/main/java/com/agrhub/sensehub/components/util/ConfigHelper.java
// public class ConfigHelper {
//     private static final String TAG = "Helper";
// 
//     /*
//     * open config file: assets/configs/config_mqtt.properties and add some values:
// 
//         api_url=http://url.to.api/v1/
//         api_key=123456
//     * */
//     public static String getConfigValue(Context context, String fileName, String name) {
//         try {
//             InputStream rawResource = context.getAssets().open(fileName);
//             Properties properties = new Properties();
//             properties.load(rawResource);
//             return properties.getProperty(name);
//         } catch (Resources.NotFoundException e) {
//             Log.e(TAG, "Unable to find the config file: " + e.getMessage());
//         } catch (IOException e) {
//             Log.e(TAG, "Failed to open config file.");
//         }
// 
//         return null;
//     }
// 
//     /*
//     * In your AndroidManifest.xml add something like:
//         ...
//         <application ...>
//             ...
// 
//             <meta-data android:name="api_url" android:value="http://url.to.api/v1/"/>
//             <meta-data android:name="api_key" android:value="123456"/>
//         </application>
//     * */
//     public static String getMetaData(Context context, String name) {
//         try {
//             ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
//                     PackageManager.GET_META_DATA);
//             Bundle bundle = ai.metaData;
//             return bundle.getString(name);
//         } catch (PackageManager.NameNotFoundException e) {
//             Log.e(TAG, "Unable to load meta-data: " + e.getMessage());
//         }
//         return null;
//     }
// }


import android.content.Context;
import android.text.TextUtils;
import com.agrhub.sensehub.components.util.ConfigHelper;
import java.util.Locale;
import javax.annotation.Nonnull;
    public String getCloudRegion() {
        return cloudRegion;
    }

    public String getBridgeHostname() {
        return bridgeHostname;
    }

    public short getBridgePort() {
        return bridgePort;
    }

    private CloudIotCoreOptions() {
    }

    public boolean isValid() {
        return !TextUtils.isEmpty(projectId) &&
                !TextUtils.isEmpty(registryId) &&
                !TextUtils.isEmpty(deviceId) &&
                !TextUtils.isEmpty(cloudRegion) &&
                !TextUtils.isEmpty(bridgeHostname);
    }

    /**
     * Construct a CloudIotCoreOptions object from SharedPreferences.
     */
    public static CloudIotCoreOptions fromConfigFile(@Nonnull Context context) {
        try {
            String fileName = "configs/config_iot_core.properties";
            CloudIotCoreOptions options = new CloudIotCoreOptions();
// Path: app/src/main/java/com/agrhub/sensehub/components/util/ConfigHelper.java
// public class ConfigHelper {
//     private static final String TAG = "Helper";
// 
//     /*
//     * open config file: assets/configs/config_mqtt.properties and add some values:
// 
//         api_url=http://url.to.api/v1/
//         api_key=123456
//     * */
//     public static String getConfigValue(Context context, String fileName, String name) {
//         try {
//             InputStream rawResource = context.getAssets().open(fileName);
//             Properties properties = new Properties();
//             properties.load(rawResource);
//             return properties.getProperty(name);
//         } catch (Resources.NotFoundException e) {
//             Log.e(TAG, "Unable to find the config file: " + e.getMessage());
//         } catch (IOException e) {
//             Log.e(TAG, "Failed to open config file.");
//         }
// 
//         return null;
//     }
// 
//     /*
//     * In your AndroidManifest.xml add something like:
//         ...
//         <application ...>
//             ...
// 
//             <meta-data android:name="api_url" android:value="http://url.to.api/v1/"/>
//             <meta-data android:name="api_key" android:value="123456"/>
//         </application>
//     * */
//     public static String getMetaData(Context context, String name) {
//         try {
//             ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(),
//                     PackageManager.GET_META_DATA);
//             Bundle bundle = ai.metaData;
//             return bundle.getString(name);
//         } catch (PackageManager.NameNotFoundException e) {
//             Log.e(TAG, "Unable to load meta-data: " + e.getMessage());
//         }
//         return null;
//     }
// }


// Path: app/src/main/java/com/agrhub/sensehub/components/mqtt/cloudiot/CloudIotCoreOptions.java
import android.content.Context;
import android.text.TextUtils;
import com.agrhub.sensehub.components.util.ConfigHelper;
import java.util.Locale;
import javax.annotation.Nonnull;

    public String getCloudRegion() {
        return cloudRegion;
    }

    public String getBridgeHostname() {
        return bridgeHostname;
    }

    public short getBridgePort() {
        return bridgePort;
    }

    private CloudIotCoreOptions() {
    }

    public boolean isValid() {
        return !TextUtils.isEmpty(projectId) &&
                !TextUtils.isEmpty(registryId) &&
                !TextUtils.isEmpty(deviceId) &&
                !TextUtils.isEmpty(cloudRegion) &&
                !TextUtils.isEmpty(bridgeHostname);
    }

    /**
     * Construct a CloudIotCoreOptions object from SharedPreferences.
     */
    public static CloudIotCoreOptions fromConfigFile(@Nonnull Context context) {
        try {
            String fileName = "configs/config_iot_core.properties";
            CloudIotCoreOptions options = new CloudIotCoreOptions();
            options.projectId = ConfigHelper.getConfigValue(context, fileName,"PROJECT_ID");