package es.verdnatura.domain

import com.google.gson.JsonObject
import es.verdnatura.presentation.common.itemBarCodeSalix
import es.verdnatura.presentation.common.packingSiteSalix
import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO
import es.verdnatura.presentation.view.feature.ajustes.model.Train
import es.verdnatura.presentation.view.feature.articulo.model.AddressLoses
import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingType
import es.verdnatura.presentation.view.feature.calidad.model.BuyerVO
import es.verdnatura.presentation.view.feature.collection.SalixSaleQuantity
import es.verdnatura.presentation.view.feature.collection.listSaleSalix
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.model.DeviceId
import es.verdnatura.presentation.view.feature.delivery.model.Expeditions
import es.verdnatura.presentation.view.feature.delivery.model.RouteInfo
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.ShelvingLogSalix
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventoryParking
import es.verdnatura.presentation.view.feature.login.model.DataUserSalix
import es.verdnatura.presentation.view.feature.login.model.LoginSalixVO
import es.verdnatura.presentation.view.feature.login.model.OperatorSalix
import es.verdnatura.presentation.view.feature.login.model.RenewToken
import es.verdnatura.presentation.view.feature.login.model.SalixGrupo
import es.verdnatura.presentation.view.feature.login.model.accessConfigSalix
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
import es.verdnatura.presentation.view.feature.packaging.model.ItemSupplier
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO
import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix
import es.verdnatura.presentation.view.feature.workermistake.model.MistakeType
import es.verdnatura.presentation.view.feature.workermistake.model.SaleMistakeSalix
import es.verdnatura.presentation.view.feature.workermistake.model.WorkerMistakeSalix
import okhttp3.MultipartBody
import retrofit2.Call
import retrofit2.http.*

interface SalixService {

    @POST("Accounts/login")
    fun login(
        @Body params: LoginSalixVO
    ): Call<LoginSalixVO>

    @GET("VnUsers/getCurrentUserData")
    fun getCurrentUserData(
    ): Call<DataUserSalix>

    /*  @POST("chats/sendCheckingPresence")
      fun sendChekingPresence(
          @Body params: SalixMessageVO
      ):
              Call<Boolean>

      @POST("chats/send")
      fun sendGroup(
          @Body params: SalixGrupo
      ):
              Call<Boolean>*/

    @GET("collections/getSectors")
    fun getSectorsSalix(
    ): Call<List<SectorItemVO>>

    @GET("collections/getCollection")
    fun getCollectionSalix(
    ): Call<List<CollectionVO>>

    @GET("Addresses/getAddress")
    fun getAddressSalix(
    ): Call<List<AddressLoses>>

    @GET("Buyers")
    fun getBuyers(
    ): Call<List<BuyerVO>>

    @GET("collections/getCollection")
    fun getCollectionSalixLocal(
    ): Call<List<CollectionTicket>>

    @POST("routes/{id}/driver-route-email")
    fun driverRouteEmail(
        @Path("id") id: Number,
        @Body params: Any
    ): Call<Any>

    @POST("collections/{id}/getTickets")
    fun getCollectionTickets(
        @Path("id") id: Number,
        @Body params: Any
    ): Call<CollectionTicket>

    @GET("collections/sectorCollection_get")
    fun sectorCollection_get(
    ): Call<List<CollectionVO>>

    @POST("collections/setSaleQuantity")
    fun collectionIncreaseQuantitySalix(
        @Body params: SalixSaleQuantity
    ): Call<Any>

    @Multipart
    @POST("Entries/{id}/uploadFile")
    fun uploadEntryPhoto(
        @Path("id") id: Number,
        @Query("warehouseId") warehouseId: Number,
        @Query("companyId") companyId: Number,
        @Query("dmsTypeId") dmsTypeId: Number,
        @Query("reference") reference: String,
        @Query("description") description: String,
        @Query("hasFile") hasFile: Boolean,
        @Part file: MultipartBody.Part,
    ): Call<Any>

    @Multipart
    @POST("dms/uploadFile")
    fun imageUpload(
        @Query("warehouseId") warehouseId: Number,
        @Query("companyId") companyId: Number,
        @Query("dmsTypeId") dmsTypeId: Number,
        @Query("reference") reference: String,
        @Query("description") description: String,
        @Query("hasFile") hasFile: Boolean,
        @Part file: MultipartBody.Part,
    ): Call<Any>

    @Multipart
    @POST("/api/Tickets/saveSign")
    fun saveSign(
        @Part file: MultipartBody.Part?, @QueryMap(encoded = true) queryMap: Map<String?, String?>
    ): Call<Any>


    @POST("Entries/{id}/addFromBuy")
    fun addFromBuy(
        @Path("id") id: Number,
        @Query("item") item: Number,
        @Query("printedStickers") printedStickers: Number
    ): Call<Any>


    @POST("tickets/{idTicket}/transferSales") //-->saleMove en Silex
    fun transferSalesSalix(
        @Path("idTicket") idTicket: String, @Body params: listSaleSalix
    ): Call<Any>

    @GET("Departments")
    fun department_getHasMistake(
        @Query("filter") filter: String = """{"fields": {"id": true,"name": true},"where": {"hasToMistake": true}}"""
    ): Call<List<DepartmentMistake>>

    @GET("Workers/findOne?")
    fun worker_idF11Allowed(
        @Query("filter") filter: String
    ): Call<JsonObject>

    @DELETE("ExpeditionPallets/{id}")
    fun expeditionPalletDel(
        @Path("id") id: Number
    ): Call<Any>

    @DELETE("ExpeditionScans/{id}")
    fun expeditionScanDel(
        @Path("id") id: Number
    ): Call<Any>

    @DELETE("ItemShelvings/{id}")
    fun itemShelvingsDelete(
        @Path("id") id: Number
    ): Call<Any>

    @GET("Workers/{idWorker}/sip")
    fun sip_getExtension(
        @Path("idWorker") idWorker: Int,
    ): Call<Any>

    @PATCH("Items/{itemFk}")
    fun update_ItemPackingType(
        @Path("itemFk") itemFk: String,
        @Body params: Any
    ): Call<Any>

    @PATCH("Items/{itemFk}")
    fun updateItem(
        @Path("itemFk") itemFk: Int,
        @Body params: Any
    ): Call<Any>

    @POST("Items/setVisibleDiscard")
    fun setVisibleDiscard(
        @Body params: Any
    ): Call<Any>

    @POST("Shelvings/upsertWithWhere")
    fun updateShelvingPriority(
        @Query("where") where: String,
        @Body params: Any
    ): Call<Any>

    //DE MOMENTO NO FUNCIONA, SE QUERÍA AÑADIR POR INSERTIGNORE
    @POST("Operators/upsertWithWhere")
    fun operatorAdd(
        @Query("where") where: String,
        @Body params: Any
    ): Call<Any>

    @POST("DeviceLogs")
    fun deviceLogInsert(
        @Body params: Any
    ): Call<Unit>

    @POST("ExpeditionTrucks")
    fun expeditionTrucksInsert(
        @Body params: Any
    ): Call<Any>

    @GET("ItemPackingTypes")
    fun get_ItemPackingType(
        @Query("filter") filter: String = """{"where": {"isActive": true}}"""
    ): Call<List<ItemPackingType>>

    @GET("ExpeditionTrucks")
    fun expeditionTruckGet(
        @Query("filter") filter: String
    ): Call<List<ItemExpeditionTruckVO>>

    @POST("PackingSiteAdvanceds")
    fun ticket_advancePackaging(
        @Body parms: packingSiteSalix
    ): Call<Unit>


    @PUT("ItemBarCodes")//REVISADA
    fun barcodes_edit(
        @Body params: itemBarCodeSalix
    ): Call<Any>

    @DELETE("ItemBarCodes")//REVISADA
    fun deleteItemBarCode(
        @Body params: itemBarCodeSalix
    ): Call<Any>


    @GET("ItemBarCodes/{barCodeValue}/toItem")//REVISADA
    fun barcodes_toitem(
        @Path("barCodeValue") barCodeValue: String
    ): Call<String?>

    @GET("Suppliers")//REVISADA
    fun getSuppliers(
        //@Body params:JSONObject=JSONObject("""filter"={"fields":{"id":true,"name":true},"include":[{"relation":"contacts","scope":{"fields":["email"],"order":"id DESC","limit":1,"where":{"email":{"neq":null}}}}]}""")
        /* @Query("filter") filter:String="{\"fields\":{\"id\":true,\"name\":true},\"include\":[{\"relation\":\"contacts\"," +
                 "\"scope\":{" +
                 "\"fields\":[\"email\"],\"order\":\"id DESC\",\"limit\":1," +
                 "\"where\":{ \"email\":{\"neq\":null } }}}]})"*/

    ): Call<List<Supplier>>

    @PUT("Entries")//REVISADA
    fun Entries(
        @Body entry: EntrySalix
    ): Call<EntrySalix>

    @GET("Shelvings")
    fun Shelvings(
        @Query("filter") filter: String
    ): Call<List<ShelvingLogSalix>>

    @GET("DeviceProductions")
    fun deviceProductionsGetName(
        @Query("filter") filter: String
    ): Call<List<DeviceId>>

    @GET("Suppliers/{supplierId}/getItemsPackaging")
    fun getItemsPackaging(
        @Path("supplierId") supplierId: Int, @Query("entry") entry: Int

    ): Call<List<ItemSupplier>>

    @POST("Entries/addFromPackaging")
    fun addFromPackaging(
        @Query("supplier") supplier: Int, @Query("isTravelReception") isTravelReception: Boolean

    ): Call<EntrySalix>

    @POST("Images/upload")
    @Multipart
    fun uploadImage(
        @Query("collection") collection: String,
        @Query("id") id: Int,
        @Part filePart: MultipartBody.Part,
    ): Call<Any>


    @PATCH("Operators/{id}")
    fun update_operator(
        @Path("id") id: Number, @Body params: Any
    ): Call<Unit>

    @GET("Operators")
    fun operator_getData(
        @Query("filter") filter: String
    ): Call<List<OperatorSalix>>

    @GET("AccessTokenConfigs")
    fun getAccessTokenConfigs(
    ): Call<List<accessConfigSalix>>

    @POST("vnusers/renewToken")
    fun renewToken(
    ): Call<RenewToken>

    @PATCH("ItemShelvings/{id}")
    fun itemShelvingUpdate(
        @Path("id") id: Number,
        @Body params: Any
    ): Call<Any>

    @POST("ItemShelvings/update")
    fun itemShelvingsUpdate(
        @Query("where") where: Any,
        @Body params: Any
    ): Call<Any>


    @POST("TicketCollections/update")
    fun ticketCollectionUpdate(
        @Query("where") filter: Any,//revisar si con Any vale, update generalmente pongo json (ejemplo: itemShelvingReset)
        @Body params: Any
    ): Call<Unit>

    @POST("ItemShelvingSales/itemShelvingSaleSetQuantity")
    fun itemShelvingsConfirmRerserved(
        @Body params: Any
    ): Call<Any>

    @PATCH("ItemShelvingSales/{id}")
    fun itemShelvingsReservedUpdate(
        @Path("id") id: Number,
        @Body params: Any
    ): Call<Any>

    @POST("ItemShelvingSales/itemShelvingSale_addByCollection")
    fun itemShelvingSale_addByCollection(
        @Body params: Any,
    ): Call<Any>

    @POST("ItemShelvingSales/itemShelvingSale_addBySale")
    fun itemShelvingSale_addBySale(
        @Body params: Any,
    ): Call<Any>


    @POST("ItemShelvings/getInventory")
    fun getInventoryParking(
        @Query("parkingFrom") parkingFrom: String, @Query("parkingTo") parkingTo: String
    ): Call<List<ItemInventoryParking>>

    @PATCH("Routes/{id}")
    fun routeUpdate(
        @Path("id") id: Number,
        @Body route: RouteInfo,

        ): Call<Any>

    @GET("ExpeditionMistakeTypes")
    fun getExpeditionMistakeTypes(
    ): Call<List<MistakeType>>

    @POST("ExpeditionMistakes")
    fun expeditionMistakesAdd(
        @Body expeditionMistake: ExpeditionMistakeSalix
    ): Call<Any>

    @POST("ExpeditionStates/addExpeditionState")
    fun addExpeditionState(
        @Body params: Expeditions?
    ): Call<Unit>

    @POST("WorkerMistakes")
    fun workerMistakesAdd(
        @Body workerMistake: WorkerMistakeSalix
    ): Call<Any>

    @GET("WorkerMistakeTypes")
    fun workerMistakesTypes(
    ):   Call<List<MistakeType>>

    @POST("SaleMistakes")
    fun saleMistakeAdd(
        @Body saleMistakeSalix: SaleMistakeSalix
    ): Call<Any>

    @GET("MistakeTypes")
    fun getMistakeTypes(
    ): Call<List<MistakeTypeVO>>

    @GET("Train")
    fun getTrain(
    ): Call<List<Train>>

}

interface SalixServiceSend {

    @POST("chats/send")
    fun sendGroup(
        @Body params: SalixGrupo
    ): Call<Boolean>


}

