package it.danieleverducci.openweddingapp.networking

import android.content.Context
import android.os.Handler
import android.util.Log
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.Response
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import it.danieleverducci.openweddingapp.Config
import it.danieleverducci.openweddingapp.entities.GalleryItem
import org.json.JSONObject
import java.io.File


class GalleryItemNet(context: Context, token: String): AuthenticatedItemNet<GalleryItem>(context, token) {
    companion object {
        val TAG = "GalleryItemNet"
    }

    fun getList(page: Int, listener: OnItemListObtainedListener<GalleryItem>) {
        val url = "${Config.API_BASE_URL}${Config.API_ENDPOINT_GALLERY_ITEM}"
        super.getList(url, page, listener)
    }

    fun postItem(listener: OnItemPostedListener<GalleryItem>, item: GalleryItem) {
        val url = "${Config.API_BASE_URL}${Config.API_ENDPOINT_GALLERY_ITEM}"
        super.postItem(url, listener, item)
    }


    fun uploadItem(token: String, file: File, listener: OnGalleryItemUploadCompletedListener) {
        val uiat = UploadItemAsyncTask(token, listener)
        uiat.execute(file)
    }

    interface OnGalleryItemUploadCompletedListener {
        fun OnGalleryItemUploaded(galleryItem: GalleryItem?, error: String)
    }

    override fun newItem(jo: JSONObject): GalleryItem {
        return GalleryItem(jo)
    }
}