<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
  xmlns:android="http://schemas.android.com/apk/res/android"
  id="@moodlehq/phonegap-plugin-push" version="4.0.0-moodle.13">

  <name>Cordova Push Plugin</name>
  <description>Enable receiving push notifications on Android, iOS and Windows devices. Android uses Firebase Cloud Messaging. iOS uses Apple APNS Notifications. Windows uses Microsoft WNS Notifications.</description>

  <license>MIT</license>

  <js-module src="www/push.js" name="PushNotification">
    <clobbers target="PushNotification"/>
  </js-module>

  <engines>
    <engine name="cordova" version=">=10.0.0"/>
    <engine name="cordova-android" version=">=9.0.0"/>
    <engine name="cordova-ios" version=">=6.0.0"/>
  </engines>

  <platform name="android">
    <hook type="before_compile" src="hooks/android/beforeCompile.js"/>

    <config-file target="res/xml/config.xml" parent="/*">
      <feature name="PushNotification">
        <param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
      </feature>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/manifest">
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
      <uses-permission android:name="android.permission.WAKE_LOCK"/>
      <uses-permission android:name="android.permission.VIBRATE"/>
      <uses-permission android:name="${applicationId}.permission.PushHandlerActivity"/>
      <uses-permission android:name="${applicationId}.permission.BackgroundHandlerActivity"/>
      <permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature"></permission>
      <permission android:name="${applicationId}.permission.BackgroundHandlerActivity" android:protectionLevel="signature"></permission>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/manifest/application">
      <activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
      <activity android:name="com.adobe.phonegap.push.BackgroundHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.BackgroundHandlerActivity">
        <intent-filter>
          <action android:name="com.adobe.phonegap.push.background.MESSAGING_EVENT"/>
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
      </activity>

      <receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler"/>
      <receiver android:name="com.adobe.phonegap.push.PushDismissedHandler"/>

      <service android:name="com.adobe.phonegap.push.FCMService" android:exported="true">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
      </service>
    </config-file>

    <config-file target="config.xml" parent="/*">
      <preference name="AndroidXEnabled" value="true" />
      <preference name="GradlePluginGoogleServicesEnabled" value="true" />
      <preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />

      <preference name="GradlePluginKotlinEnabled" value="true" />
      <preference name="GradlePluginKotlinVersion" value="1.5.20" />
    </config-file>

    <preference name="ANDROIDX_CORE_VERSION" default="1.6.+"/>
    <preference name="FCM_VERSION" default="23.+"/>

    <framework src="androidx.core:core:$ANDROIDX_CORE_VERSION" />
    <framework src="me.leolin:ShortcutBadger:1.1.22@aar"/>
    <framework src="com.google.firebase:firebase-messaging:$FCM_VERSION"/>
    <framework src="com.goterl:lazysodium-android:5.2.0@aar"/>
    <framework src="net.java.dev.jna:jna:5.17.0@aar"/>

    <source-file src="src/android/com/adobe/phonegap/push/FCMService.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/PushConstants.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/BackgroundHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/PushPlugin.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/PushDismissedHandler.kt" target-dir="java/com/adobe/phonegap/push/"/>
    <source-file src="src/android/com/adobe/phonegap/push/EncryptionHandler.kt" target-dir="java/com/adobe/phonegap/push/"/>
  </platform>

  <platform name="browser">
    <js-module src="www/browser/push.js" name="BrowserPush">
      <clobbers target="PushNotification"/>
    </js-module>

    <asset src="src/browser/ServiceWorker.js" target="ServiceWorker.js"/>
    <asset src="src/browser/manifest.json" target="manifest.json"/>

    <hook type="after_prepare" src="hooks/browser/updateManifest.js"/>
  </platform>

  <platform name="ios">
    <preference name="IOS_FIREBASE_MESSAGING_VERSION" default="~> 10.23.0"/>

    <config-file target="config.xml" parent="/*">
      <feature name="PushNotification">
        <param name="ios-package" value="PushPlugin"/>
      </feature>
    </config-file>

    <config-file target="*-Info.plist" parent="UIBackgroundModes">
      <array>
        <string>remote-notification</string>
      </array>
    </config-file>

    <config-file target="*-Debug.plist" parent="aps-environment">
      <string>development</string>
    </config-file>

    <config-file target="*-Release.plist" parent="aps-environment">
      <string>production</string>
    </config-file>

    <source-file src="src/ios/AppDelegate+notification.m"/>
    <source-file src="src/ios/PushPlugin.m"/>
    <source-file src="src/ios/EncryptionHandler.m"/>
    <source-file src="src/ios/Crypto.swift"/>
    <header-file src="src/ios/AppDelegate+notification.h"/>
    <header-file src="src/ios/PushPlugin.h"/>
    <header-file src="src/ios/EncryptionHandler.h"/>

    <framework src="PushKit.framework"/>

    <podspec>
      <config>
        <source url="https://cdn.cocoapods.org/"/>
      </config>
      <pods use-frameworks="true">
        <pod name="Firebase/Messaging" spec="$IOS_FIREBASE_MESSAGING_VERSION" />
        <pod name="Sodium" git="https://github.com/jedisct1/swift-sodium.git" commit="f67e6e0" />
      </pods>
    </podspec>
  </platform>

  <platform name="windows">
    <hook type="after_plugin_install" src="hooks/windows/setToastCapable.js"/>

    <js-module src="src/windows/PushPluginProxy.js" name="PushPlugin">
      <runs/>
    </js-module>

    <config-file target="config.xml" parent="/*">
      <preference name="WindowsToastCapable" value="true"/>
    </config-file>
  </platform>
</plugin>
