export default (configuration) => {
  return `
package ${configuration.packageName}.fcm



import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ContentValues.TAG
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import ${configuration.packageName}.MainActivity
import ${configuration.name}.R
import ${configuration.packageName}.data.local.AppPreferences
import ${configuration.packageName}.extensions.Constants
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import org.koin.android.ext.android.inject

const val channelId = "Notifications"
const val channelName = "Notifications"

class MyFirebasePushNotifications : FirebaseMessagingService() {

    private val pref by inject<AppPreferences>()

    @SuppressLint("NewApi")
    override fun onMessageReceived(message: RemoteMessage) {
        Log.d(TAG, "onMessageReceived: \${message.data}")

        //Constants.hasNewNotification.postValue(true)

        if (message.data.isNotEmpty()) {
            val title = message.notification?.title
            val body = message.data["gcm.notification.body"]
            generatePushNotifications(title ?: "", body ?: "")
        } else {
            generatePushNotifications(
                message.notification?.title ?: "", message.notification?.body ?: ""
            )
        }

    }

    private fun generatePushNotifications(title: String, message: String) {
        val intent = Intent(this, MainActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

        val pendingIntent = PendingIntent.getActivity(
            this,
            0,
            intent,
            PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
        )

        val builder: NotificationCompat.Builder = NotificationCompat.Builder(
            applicationContext, channelId
        ).setSmallIcon(R.drawable.ic_loc_active).setAutoCancel(true)
            .setVibrate(longArrayOf(500, 1000, 500, 1000)).setOnlyAlertOnce(false)
            .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_loc_active)
            .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
        val notificationManager =
            getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val notificationChannel =
                NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH)
            notificationManager.createNotificationChannel(notificationChannel)
        }
        builder.setContentText(title)
        notificationManager.notify(0, builder.build())
    }

    override fun onNewToken(token: String) {
        Log.d(TAG, "Refreshed token: $token")

        pref.fcmToken = token
        Constants.FCM_TOKEN.postValue(token)
    }
}
  
  `;
};
