package es.verdnatura.domain

import android.content.Context
import es.verdnatura.presentation.common.itemBarCodeSalix
import es.verdnatura.presentation.common.itemPackingTypeSalix
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingType
import es.verdnatura.presentation.view.feature.articulo.model.ItemProposal
import es.verdnatura.presentation.view.feature.historicoarticulo.model.ItemHistoricoVO
import retrofit2.Call
import java.security.AuthProvider

class GetItemCardUserCase(context: Context) : RestClient(context) {

    fun getItemCard(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String
    ): Call<ItemCardVO> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        return restClient!!.getItemCard(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun item_getSimilar(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String,
        vshipped: String,
        vIsShowedByType: String
    ): Call<List<ItemProposal>> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        params.add(vshipped)
        params.add(vIsShowedByType)

        return restClient!!.item_getSimilar(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun getItemPackingType(usuario: String, password: String): Call<List<ItemPackingType>> {
        val params: ArrayList<String> = ArrayList()
        return restClient!!.getItemPackingType(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun getItemPackingTypeSalix(token:String): Call<List<ItemPackingType>> {
        return salixClient!!.get_ItemPackingType(
            content_type = "application/json",
            authorization = token
        )
    }

    fun itemStockUpdate(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String,
        newVisible: String,
        isTrash: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        params.add(newVisible)
        params.add(isTrash)

        //sergio: se modifica por CAU a itemTrash// Faltas también accede a itemStockUpdate)

        //return restClient!!.itemStockUpdate("json","1",usuario,password,"application/json",params = params)
        return restClient!!.itemTrash(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun itemTrash(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String,
        newVisible: String,
        isTrash: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        params.add(newVisible)
        params.add(isTrash)
        return restClient!!.itemTrash(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

  /*  fun itemPlacementSave(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String,
        value: String
    ): Call<String> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        params.add(value)
        return restClient!!.itemPlacementSave(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }*/

    fun updateGrouping(
        usuario: String,
        password: String,
        itemFk: String,
        value: String,
        warehouseFk: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(value)
        params.add(warehouseFk)
        return restClient!!.updateGrouping(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun updatePacking(
        usuario: String,
        password: String,
        itemFk: String,
        value: String,
        warehouseFk: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(value)
        params.add(warehouseFk)
        return restClient!!.updatePacking(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }
/*
    fun updatePackingType(
        usuario: String,
        password: String,
        itemFk: String,
        ItemPackingType: String
    ): Call<Boolean> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(ItemPackingType)
        return restClient!!.updatePackingType(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }*/

    fun updatePackingTypeSalix(
        token:String,
        itemFk: String,
        ItemPackingType: String
    ): Call<Any> {
        val params=itemPackingTypeSalix(ItemPackingType)

        return salixClient!!.update_ItemPackingType(
            content_type ="application/json",
            authorization = token,
            itemFk = itemFk,
            params = params
        )
    }
    fun item_saveStems(
        usuario: String,
        password: String,
        itemFk: String,
        value: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(value)
        return restClient!!.item_saveStems(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }

    fun item_saveReference(
        usuario: String,
        password: String,
        itemFk: String,
        value: String
                   ): Call<Unit> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(value)
        return restClient!!.item_saveReference(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
                                       )
    }


    fun barcodes_edit(
        usuario: String,
        password: String,
        itemFk: String,
        value: String,
        delete: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(value)
        params.add(itemFk)
        params.add(delete)
        return restClient!!.barcodes_edit(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }


    fun barcodes_editSalix(
        token:String,
        itemFk: String,
        value: String,

    ): Call<Any> {

        return salixClient!!.barcodes_edit(
            content_type = "application/json",
            authorization=token,
            itemBarCodeSalix(itemFk,value)
        )
    }


    fun itemDiary(
        usuario: String,
        password: String,
        itemFk: String,
        warehouseFk: String
    ): Call<List<ItemHistoricoVO>> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemFk)
        params.add(warehouseFk)
        return restClient!!.itemDiary(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params = params
        )
    }
}