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

import com.example.ops_android.data.model.OrderCounts
import com.example.ops_android.data.model.Cost
import com.example.ops_android.data.model.PurchaseCommit
import com.example.ops_android.data.model.PurchaseOrder
import com.example.ops_android.data.model.PurchasePhoto
import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body
import retrofit2.http.POST

data class GetOrdersRequest(
    val status: String? = null,
    val search: String? = null,
    val entries: Int = 20,
    val page: Int = 1
)

data class OrdersListResponse(
    val all_orders: List<PurchaseOrder>?,
    val all_count: Int = 0
)

data class GetOrderRequest(
    val id: Int
)

data class UpdateOrderStatusRequest(
    val id: Int,
    val status: String,
    val comment: String? = null,
    val photos: List<String>? = null
)

data class OrderDetailResponse(
    val order: PurchaseOrder?,
    val costs: List<Cost>?,
    val photos: List<PurchasePhoto>?,
    val commits: List<PurchaseCommit>?,
    val canModify: Boolean = false
)

interface PurchaseApi {

    @POST("/purchase/getorders")
    suspend fun getOrders(@Body request: GetOrdersRequest): ApiResponse<OrdersListResponse>

    @POST("/purchase/getorder")
    suspend fun getOrder(@Body request: GetOrderRequest): ApiResponse<OrderDetailResponse>

    @POST("/purchase/getordercount")
    suspend fun getOrderCount(@Body request: EmptyBody = EmptyBody()): ApiResponse<OrderCounts>

    @POST("/purchase/updatestatus")
    suspend fun updateOrderStatus(@Body request: UpdateOrderStatusRequest): ApiResponse<Any>

    @POST("/purchase/addorder")
    suspend fun addOrder(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/purchase/updateorder")
    suspend fun updateOrder(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>
}
