<?xml version="1.0" encoding="UTF-8" ?>
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
    id="@bluedot-innovation/cordova-plugin"
    version="3.0.0">

    <dependency id="cordova-plugin-device" version="2.0.3" />
    
    <engines>
        <engine name="cordova" version=">=9.0.0" />
    </engines>

    <name>Bluedot Point SDK</name>

    <js-module src="www/bluedotPointSDKCDVPlugin.js" name="BluedotPointSDKCDVPlugin">
        <clobbers target="io.bluedot.cordova.plugin" />
    </js-module>

    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="BDPointSDK">
                <param name="ios-package" value="BluedotPointSDKCDVPlugin" />
            </feature>
        </config-file>

        <!-- The app provides a description for the use of background location updates -->
        <config-file target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
            <string>Allow location-based actions to be triggered while in the background</string>
        </config-file>

        <config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
            <string>Allow location-based actions to be triggered while in use</string>
        </config-file>

        <config-file target="*-Info.plist" parent="NSLocationAlwaysAndWhenInUseUsageDescription">
            <string>Allow location-based actions to be triggered while in use and in the background</string>
        </config-file>

        <!-- The app is able to run in background through location updates -->
        <config-file target="*-Info.plist" parent="UIBackgroundModes">
            <array>
                <string>location</string>
            </array>
        </config-file>
        <header-file src="src/ios/BluedotPointSDKCDVPlugin.h" />
        <source-file src="src/ios/BluedotPointSDKCDVPlugin.m" />

        <!--  The following lists the frameworks required for building the SDK -->
        <framework src="CoreLocation.framework" />
        <framework src="CoreMotion.framework" />
        <framework src="CoreGraphics.framework" />
        <framework src="CoreData.framework" />
        <framework src="MapKit.framework" />
        <framework src="UIKit.framework" />
        <framework src="SystemConfiguration.framework" />

        <!-- Point SDK -->
        <podspec>
            <config>
                <source url="https://github.com/CocoaPods/Specs.git"/>
            </config>
            <pods use-frameworks="true">
                <pod name="BluedotPointSDK" spec="~> 15.6.0" />
            </pods>
        </podspec>
    </platform>

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="BDPointSDK" >
                <param name="android-package" value="io.bluedot.cordova.plugin.BDPointSDKWrapper"/>
            </feature>
        </config-file>

        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <receiver
                    android:name="io.bluedot.cordova.plugin.BDPointSDKWrapper$BluedotErrorReceiver"
                    android:enabled="true"
                    android:exported="false">
                <intent-filter>
                    <action android:name="io.bluedot.point.SERVICE" />
                </intent-filter>
            </receiver>
        </config-file>

        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <receiver
                    android:name="io.bluedot.cordova.plugin.BDPointSDKWrapper$BluedotGeoTriggerReceiver"
                    android:enabled="true"
                    android:exported="false">
                <intent-filter>
                    <action android:name="io.bluedot.point.GEOTRIGGER" />
                </intent-filter>
            </receiver>
        </config-file>

        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <receiver
                    android:name="io.bluedot.cordova.plugin.BDPointSDKWrapper$BluedotTempoReceiver"
                    android:enabled="true"
                    android:exported="false">
                <intent-filter>
                    <action android:name="io.bluedot.point.TEMPO" />
                </intent-filter>
            </receiver>
        </config-file>

        <!-- Adding custom gradle file to import Bluedot Android Point SDK Dependency -->
        <framework src="src/android/bluedotplugin.gradle" custom="true" type="gradleReference"/>
        <config-file target="config.xml" parent="/*">
            <preference name="GradlePluginGoogleServicesEnabled" value="true" />
            <preference name="GradlePluginGoogleServicesVersion" value="4.2.0" />
        </config-file>

        <!-- google-play-services is not used by Bluedot Point SDK but is required for installing security providers https://developer.android.com/training/articles/security-gms-provider.html -->
        <framework src="com.google.android.gms:play-services-base:17.6.0" />
        
        <source-file src="src/android/BDPointSDKWrapper.java" target-dir="src/io/bluedot/cordova/plugin" />

    </platform>
</plugin>
