

package com.ejada.hmg.geofence.intent_receivers

import android.content.Context
import com.ejada.hmg.R
import com.ejada.hmg.geofence.HMG_Geofence
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.location.GeofenceStatusCodes

object GeofenceErrorMessages {
  fun getErrorString(context: Context, e: Exception): String {
    return if (e is ApiException) {
      getErrorString(context, e.statusCode)
    } else {
      context.resources.getString(R.string.geofence_unknown_error)
    }
  }

  fun getErrorString(context: Context, errorCode: Int): String {
    val resources = context.resources
    val errorMessage = when (errorCode) {
      GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE ->
        resources.getString(R.string.geofence_not_available)

      GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES ->
        resources.getString(R.string.geofence_too_many_geofences)

      GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS ->
        resources.getString(R.string.geofence_too_many_pending_intents)

      GeofenceStatusCodes.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION ->
        resources.getString(R.string.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION)

      GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT ->
        resources.getString(R.string.GEOFENCE_REQUEST_TOO_FREQUENT)

      else -> resources.getString(R.string.geofence_unknown_error)
    }

    return  errorMessage
  }
}