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

import com.example.ops_android.data.model.PurchaseOrder
import com.example.ops_android.data.model.PurchaseOrderInfo
import com.example.ops_android.data.model.TabFileInfo
import com.example.ops_android.data.model.WorkOrder
import com.example.ops_android.data.model.WorkOrderCommit
import com.example.ops_android.data.model.WorkOrderCounts
import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body
import retrofit2.http.POST

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

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

data class WorkOrderGetRequest(
    val id: Int
)

data class WorkOrderDetailResponse(
    val order: WorkOrder?,
    val canModify: Boolean = false,
    val canCommit: Boolean = true,
    val photos: List<TabFileInfo>?,
    val commits: List<WorkOrderCommit>?,
    val linkedItems: List<LinkedItem>?,
    val linkedCustomers: List<LinkedCustomer>?
)

data class LinkedItem(
    @com.google.gson.annotations.SerializedName("ID") val id: Int = 0,
    @com.google.gson.annotations.SerializedName("Name") val name: String? = null,
    @com.google.gson.annotations.SerializedName("SerialNumber") val serialNumber: String? = null,
    @com.google.gson.annotations.SerializedName("ContainerID") val containerId: Int? = null
)

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

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

data class SearchPurchaseOrdersRequest(
    val search: String,
    val limit: Int = 10
)

data class SearchPurchaseOrdersResponse(
    val orders: List<PurchaseOrderInfo>?
)

interface WorkOrderApi {

    @POST("/work_order/list")
    suspend fun list(@Body request: WorkOrderListRequest): ApiResponse<WorkOrderListResponse>

    @POST("/work_order/get")
    suspend fun get(@Body request: WorkOrderGetRequest): ApiResponse<WorkOrderDetailResponse>

    @POST("/work_order/count")
    suspend fun getCount(@Body request: EmptyBody = EmptyBody()): ApiResponse<WorkOrderCounts>

    @POST("/work_order/add")
    suspend fun add(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

    @POST("/work_order/update")
    suspend fun update(@Body request: Map<String, @JvmSuppressWildcards Any>): ApiResponse<Any>

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

    @POST("/work_order/commit")
    suspend fun commit(@Body request: WorkOrderCommitRequest): ApiResponse<Any>

    @POST("/work_order/search_purchase_orders")
    suspend fun searchPurchaseOrders(@Body request: SearchPurchaseOrdersRequest): ApiResponse<SearchPurchaseOrdersResponse>
}
