package es.verdnatura.domain

import android.content.Context
import es.verdnatura.presentation.view.feature.collection.*
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO
import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO
import retrofit2.Call

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

    //sergio: se quita para ir colocando collection_getTickets
    /* fun collectionTicketGet(usuario:String,password:String,collectionFk:String,sectorFk:String,print:String,type:String) : Call<CollectionVO> {
         val params:ArrayList<String> = ArrayList()
         params.add(collectionFk)
         params.add(sectorFk)
         params.add(print)
         params.add(type)
         return restClient!!.collectionTicketGet("json","1",usuario,password,"application/json",params)
     }*/
    //sergio: se cambia llamada a collection_getTickets

    fun collectionTicketGet(
        usuario: String,
        password: String,
        collectionFk: String,
        sectorFk: String,
        print: String,
        type: String
    ): Call<CollectionVO> {
        val params: ArrayList<String> = ArrayList()
        params.add(collectionFk)
        params.add(sectorFk)
        params.add(print)
        params.add(type)
        return restClient!!.collection_getTickets(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

    fun sip_getExtensionSalix(
        token:String,
        WorkerId: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(WorkerId)
        return salixClient!!.sip_getExtension(
            content_type = "application/json",
            authorization = token,
            idWorker=WorkerId
        )
    }

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


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

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

    fun collection_assign(
        usuario: String,
        password: String
    ): Call<String> {

        return restClient!!.collection_assign(
            "json",
            "1",
            usuario,
            password,
            "application/json"
        )

    }


    fun collectionNew(
        usuario: String,
        password: String,
        sectorFk: String,
        carros: String
    ): Call<String> {
        val params: ArrayList<String> = ArrayList()
        params.add(sectorFk)
        params.add(carros)
        return restClient!!.collectionNew(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )

    }

    fun collectionNewSmarttag(
        usuario: String,
        password: String,
        sectorFk: String,
        carros: String,
        tagtype: String
    ): Call<String> {
        val params: ArrayList<String> = ArrayList()
        params.add(sectorFk)
        params.add(carros)
        params.add(tagtype)
        return restClient!!.collectionNew(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )

    }

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



    fun collectionGetSalix(token:String): Call<List<CollectionVO>> {
        // val params:ArrayList<String> = ArrayList()
        return salixClient!!.getCollectionSalix(content_type = "application/json", authorization = token)
    }

    fun saleTrackingReplace(
        usuario: String,
        password: String,
        saleFk: String,
        vOriginalQuantity: String,
        vStateFk: String,
        vIsChecked: String,
        vBuyFk: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        params.add(vOriginalQuantity)
        params.add(vStateFk)
        params.add(vIsChecked)
        params.add(vBuyFk)
        return restClient!!.saleTrackingReplace(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

    fun saleTracking_mark(
        usuario: String,
        password: String,
        saleFk: String,
        vOriginalQuantity: String,
        vStateFk: String,
        vIsChecked: String,
        vBuyFk: String,
        vItemShelvingFk:String,
        vQuantity:String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        params.add(vOriginalQuantity)
        params.add(vStateFk)
        params.add(vIsChecked)
        params.add(vBuyFk)
        params.add(vItemShelvingFk) //Tarea #4371 Se añade para transaccionar los dos proced asociados
        params.add(vQuantity)
        return restClient!!.saleTracking_mark(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }


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

    fun itemShelvingSaleSupplyAdd(
        usuario: String,
        password: String,
        itemShelvingFk: String,
        saleFk: String,
        quantity: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemShelvingFk)
        params.add(saleFk)
        params.add(quantity)
        return restClient!!.itemShelvingSaleSupplyAdd(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

    fun itemShelvingPlacementSupplyAdd(
        usuario: String,
        password: String,
        itemShelvingFk: String,
        itemPlacementSupplyFk: String,
        quantity: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(itemShelvingFk)
        params.add(itemPlacementSupplyFk)
        params.add(quantity)
        return restClient!!.itemShelvingPlacementSupplyAdd(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

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

    fun ticketCollection_setUsedShelves(
        usuario: String,
        password: String,
        ticketFk: String,
        usedShelves: String
    ): Call<Void> {
        val params: ArrayList<String> = ArrayList()
        params.add(ticketFk)
        params.add(usedShelves)
        return restClient!!.ticketCollection_setUsedShelves(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

    fun item_updatePackingShelve(
        usuario: String,
        password: String,
        vSelf : String,
        vPacking : String
    ): Call<Void> {
        val params: ArrayList<String> = ArrayList()
        params.add(vSelf)
        params.add(vPacking)
        return restClient!!.item_updatePackingShelve(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }


    fun saleTracking_add(
        usuario: String,
        password: String,
        saleGroupFk: String
    ): Call<Void> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleGroupFk)
        return restClient!!.saleTracking_add(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

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

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

    fun saleMove(
        usuario: String,
        password: String,
        saleFk: String,
        quantity: String,
        originalQuantity: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        params.add(quantity)
        params.add(originalQuantity)
        return restClient!!.saleMove("json", "1", usuario, password, "application/json", params)
    }

    fun collectionMissingTrash(
        usuario: String,
        password: String,
        saleFk: String,
        quantity: String,
        type: String,
        warehouseFk: String,
        originalQuantity: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        params.add(quantity)
        params.add(type)
        params.add(warehouseFk)
        params.add(originalQuantity)
        return restClient!!.collectionMissingTrash(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

    fun saleTrackingDel(usuario: String, password: String, saleFk: String): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        return restClient!!.saleTrackingDel(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }
    fun itemShelving_updateFromSale(usuario: String, password: String, saleFk: String,visible:String): Call<Unit> {
        val params: ArrayList<String> = ArrayList()
        params.add(saleFk)
        params.add(visible)
        return restClient!!.itemShelving_updateFromSale(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }
    fun ticket_setState(
        usuario: String,
        password: String,
        ticketFk: String,
        state: String
    ): Call<Unit> {
        val params: ArrayList<String> = ArrayList()
        params.add(ticketFk)
        params.add(state)
        return restClient!!.ticket_setState(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }
        fun debug_add(
            usuario: String,
            password: String,
            buyFk: String,
            message: String
        ): Call<Unit> {
            val params: ArrayList<String> = ArrayList()
            params.add(buyFk)
            params.add(message)
            return restClient!!.debug_add(
                "json",
                "1",
                usuario,
                password,
                "application/json",
                params
            )

    }


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

    fun getIdFromCodeSalix(token: String, barCodeValue: String): Call<String> {

        return salixClient!!.barcodes_toitem(
            "application/json",
            authorization = token,
            barCodeValue=barCodeValue

        )
    }

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

    fun transferSalesSalix(

        token: String,
        ticketFk:String,
        saleFk: String,
        quantity: String,

    ): Call<Any> {

        var saleTransfer = listSaleSalix(mutableListOf())
        saleTransfer.sales.add(saleSalix(id = saleFk.toInt(), quantity = quantity.toInt()))


        return salixClient!!.transferSalesSalix(
            "json",
            "1",
            token,
            "application/json",
            ticketFk,
            saleTransfer

        )
    }


    fun collectionIncreaseQuantitySalix(

        token: String,
        saleFk: String,
        quantity: String
    ): Call<Any> {


        return salixClient!!.collectionIncreaseQuantitySalix(
            "json",
            "1",
            token,
            "application/json",
            SalixSaleQuantity(saleId = saleFk.toInt(), quantity = quantity.toInt())

        )
    }

    fun saleMistakeAdd(
        usuario: String,
        password: String,
        vSaleFk: String,
        vUserFk: String,
        vTypeFk: String
    ): Call<Any> {
        val params: ArrayList<String> = ArrayList()
        params.add(vSaleFk)
        params.add(vUserFk)
        params.add(vTypeFk)
        return restClient!!.saleMistakeAdd(
            "json",
            "1",
            usuario,
            password,
            "application/json",
            params
        )
    }

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

}
