package es.verdnatura.presentation.common

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class FunctionUtils{
    fun getMessageFromJSON(json: String): String {
        val gson = Gson()
        var message = ""
        var tutorialMap: Map<String, Any> =
            gson.fromJson(json, object : TypeToken<Map<String, Any>>() {}.type)
        tutorialMap.forEach {
            if (it.key.equals("Message")) {
                message = it.value.toString()
            }
        }
        return message
    }

    fun getListFromJSON(json: String): List<String> {
        val gson = Gson()
        var list = mutableListOf<String>()
        //  val mapType = object : TypeToken<Map<String, Any>>() {}.type
        var tutorialMap: Map<String, Any> =
            gson.fromJson(json, object : TypeToken<Map<String, Any>>() {}.type)
        tutorialMap.forEach {

            list.add(it.key + ":" + it.value)

        }
        return list
    }
}