package es.verdnatura.presentation.base

import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.ViewModel
import org.json.JSONObject

abstract class BaseViewModel : ViewModel(), LifecycleObserver


fun nameofFunction(function: Any): String {
    // return Thread.currentThread().stackTrace[1].methodName
    try {
        return function.javaClass.enclosingMethod!!.name
    } catch (e: Exception) {
        return "ActivityMain"
    }
}

fun getMessageFromAllResponse(callFunction: String, ResponseMessage: String): String {

    var messageFromError: String
    val returnMessage: String

    try {
        val answerError = JSONObject(ResponseMessage)
        messageFromError = answerError.get("Message").toString()
    } catch (e: Exception) {
        messageFromError = ResponseMessage
    }


    //sergio:para personalizar los mensajes de respuesta según la llamada.
 /*   when (callFunction) {
        //"collection_getTickets_" -> returnMessage ="No hay tickets para sacar. Llamada $callFunction."
        else -> {*/
            returnMessage = "Callback: $callFunction."
       // }
   // }

    return "$messageFromError.\r$returnMessage"

}
