package com.example.ops_android.data.remote.api

import com.example.ops_android.data.model.Container
import com.example.ops_android.data.model.Item
import com.example.ops_android.data.model.TabFileInfo
import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body
import retrofit2.http.POST

data class ListContainerRequest(
    val parent_id: Int? = null
)

data class ListContainerResponse(
    val containers: List<Container>?
)

data class GetContainerRequest(
    val id: Int
)

data class ContainerResponse(
    val container: Container?
)

data class ListItemRequest(
    val container_id: Int? = null,
    val search: String? = null,
    val entries: Int = 10,
    val page: Int = 1
)

data class ListItemResponse(
    val items: List<Item>?
)

data class GetItemRequest(
    val id: Int
)

data class ItemResponse(
    val item: Item?,
    val photos: List<TabFileInfo>? = null,
    val commits: List<ItemCommitDetail>? = null,
    val work_orders: List<LinkedWorkOrder>? = null,
    val customers: List<LinkedCustomerInfo>? = null,
    val canModifyItem: Boolean = false,
    val container_breadcrumb: String? = null
)

data class ItemCommitDetail(
    val ID: Int = 0,
    val ItemID: Int = 0,
    val UserID: Int = 0,
    val OldContainerBreadcrumb: String? = null,
    val NewContainerBreadcrumb: String? = null,
    val Remark: String? = null,
    val CreatedAt: String? = null
)

data class LinkedWorkOrder(
    val id: Int = 0,
    val title: String? = null,
    val status: String? = null
)

data class LinkedCustomerInfo(
    val id: Int = 0,
    val first_name: String? = null,
    val last_name: String? = null,
    val title: String? = null,
    val primary_phone: String? = null
)

data class MoveItemRequest(
    val item_id: Int,
    val new_container: Int? = null
)

data class WarehouseCountResponse(
    val container_total: Int = 0,
    val item_total: Int = 0,
    val unstored_items: Int = 0
)

interface WarehouseApi {

    @POST("/warehouse/list_container")
    suspend fun listContainer(@Body request: ListContainerRequest): ApiResponse<ListContainerResponse>

    @POST("/warehouse/get_container")
    suspend fun getContainer(@Body request: GetContainerRequest): ApiResponse<ContainerResponse>

    @POST("/warehouse/add_container")
    suspend fun addContainer(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/warehouse/update_container")
    suspend fun updateContainer(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/warehouse/delete_container")
    suspend fun deleteContainer(@Body request: Map<String, @JvmSuppressWildcards Int>): ApiResponse<Any>

    @POST("/warehouse/list_item")
    suspend fun listItem(@Body request: ListItemRequest): ApiResponse<ListItemResponse>

    @POST("/warehouse/get_item")
    suspend fun getItem(@Body request: GetItemRequest): ApiResponse<ItemResponse>

    @POST("/warehouse/add_item")
    suspend fun addItem(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/warehouse/update_item")
    suspend fun updateItem(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/warehouse/delete_item")
    suspend fun deleteItem(@Body request: Map<String, @JvmSuppressWildcards Int>): ApiResponse<Any>

    @POST("/warehouse/move_item")
    suspend fun moveItem(@Body request: MoveItemRequest): ApiResponse<Any>

    @POST("/warehouse/count")
    suspend fun getCount(@Body request: EmptyBody = EmptyBody()): ApiResponse<WarehouseCountResponse>
}
