package it.danieleverducci.openweddingapp.networking

import android.content.Context
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.VolleyError
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import it.danieleverducci.openweddingapp.Config
import it.danieleverducci.openweddingapp.entities.Location
import org.json.JSONObject


class PlacesNet(context: Context) {
    companion object {
        val TAG = "PlacesNet"
        val url = "${Config.API_BASE_URL}${Config.STATIC_ENDPOINT_PLACES}"
    }

    val queue: RequestQueue

    init {
        queue = Volley.newRequestQueue(context)
    }

    open fun getItem(listener: OnItemObtainedListener) {
        val request = JsonObjectRequest(
            Request.Method.GET,
            url,
            null,
            {
                listener.OnItemObtained(it)
            },
            {
                listener.OnError(it)
            })
        queue.add(request)
    }

    interface OnItemObtainedListener {
        fun OnItemObtained(item: JSONObject)
        fun OnError(error: VolleyError)
    }

}