package com.iscs.bozzys.api

import com.google.gson.JsonObject
import okhttp3.MultipartBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.HeaderMap
import retrofit2.http.Headers
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Query
import retrofit2.http.QueryMap

/**
 * 接口定义层
 */
interface ApiService {

    /**
     * 登录
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/system/auth/login")
    suspend fun login(
        @Body body: JsonObject,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponseLogin>

    /**
     * 退出登录
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/system/auth/logout")
    suspend fun logout(@HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()): Response<Boolean>

    /**
     * 刷新Token使用
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/system/auth/refresh-token")
    suspend fun refreshToken(
        @Query("refreshToken") refreshToken: String,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponseLogin>

    /**
     * 获取用户权限信息
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/system/auth/get-permission-info")
    suspend fun getUserPermission(
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePermission>

    /**
     * 获取作业列表数据
     *
     * app /admin-api/adroid/iscs/workflow/getAppMyTicketPage
     * web /admin-api/iscs/workflow-work/getWorkflowWorkPage
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/adroid/iscs/workflow/getAppMyTicketPage")
    suspend fun getJobs(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<Job>>

    /**
     * 获取任务列表数据
     * app /admin-api/adroid/iscs/workflow/getAppMyWorkPage
     * web /admin-api/iscs/workflow-work/getMyWorkPage
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/adroid/iscs/workflow/getAppMyWorkPage")
    suspend fun getTasks(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<Task>>

    /**
     * 查询任务数统计
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/adroid/iscs/workflow/getAppHomeStatistics")
    suspend fun getTaskStatistics(@HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()): Response<TaskStatistics>

    /**
     * 通过节点Id获取任务信息
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/iscs/workflow-work/getMyWorkNodeDetail")
    suspend fun getTaskInfo(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Node>

    /**
     * 获取当前任务的表单信息
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/bpm/form/get")
    suspend fun getTaskFormInfo(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<TaskFormInfo>

    /**
     * 获取字典数据
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/system/dict-data/page")
    suspend fun getDictData(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<Dict>>

    /**
     * 获取SOP模板列表
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/iscs/workflow-design/getWorkflowDesignPage")
    suspend fun getSopList(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<Sop>>

    /**
     * 创建作业
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/iscs/workflow-work/insertWorkflowWork")
    suspend fun createJob(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Any>

    /**
     * 编辑作业
     */
    @Headers("Content-Type: application/json")
    @PUT("/admin-api/iscs/workflow-work/updateWorkflowWork")
    suspend fun editJob(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Any>

    /**
     * 发布作业
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/iscs/workflow-work/updateStartWork")
    suspend fun pushJob(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 查询作业详情
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/iscs/workflow-work/selectWorkflowWorkById")
    suspend fun getJobById(
        @Query("id") id: Int,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Job>

    /**
     * 更新工作中的节点信息
     */
    @Headers("Content-Type: application/json")
    @PUT("/admin-api/iscs/workflow-work-node/updateWorkflowWorkNode")
    suspend fun updateJobNodeInfo(
        @Body body: MutableMap<String, Any?>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 更新当前节点任务状态
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/iscs/workflow-work/updateNodeApproval")
    suspend fun updateJobNodeApproval(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 通过角色码获取角色列表
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/system/user/getUserByRoleCode")
    suspend fun getUsersByRoleCode(
        @Query("roleCode") roleCode: String,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<List<User>>

    /**
     * 获取管理表单列表
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/bpm/form/page")
    suspend fun getBpmFormList(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<TaskFormInfo>>

    /**
     * 获取点位列表
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/iscs/isolation-point/getIsolationPointPage")
    suspend fun getIsolationPointList(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<IsolationPoint>>

    /**
     * 获取通知消息
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/system/app-notify-message/my-page")
    suspend fun getMessages(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<Message>>

    /**
     * 获取未读通知消息
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/system/app-notify-message/get-unread-count")
    suspend fun getMessagesUnread(@HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()): Response<Int>

    /**
     * 更新消息为已读
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @PUT("/admin-api/system/app-notify-message/update-read")
    suspend fun updateMessageRead(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 标记所有消息为已读
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @PUT("/admin-api/system/app-notify-message/update-all-read")
    suspend fun updateMessageAllRead(@HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()): Response<Boolean>

    /**
     * 文件上传
     */
    @Multipart
    @POST("/admin-api/infra/file/upload")
    suspend fun uploadFile(
        @Part part: MultipartBody.Part,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<String>

    /**
     * 更新用户信息
     */
    @Headers("Content-Type: application/json")
    @PUT("/admin-api/system/user/profile/update")
    suspend fun updateUserProfile(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 更新消息推送状态
     */
    @Headers("Content-Type: application/json")
    @POST("/admin-api/system/user/updateDeviceId")
    suspend fun updateMessagePushStatus(
        @Body body: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 获取当前用户人脸数据
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @GET("/admin-api/iscs/user-characteristic/getUserCharacteristicPage")
    suspend fun getUserCharacteristicList(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<ResponsePage<UserCharacteristic>>

    /**
     * 删除用户特征数据
     */
    @Headers("Content-Type: application/x-www-form-urlencoded")
    @DELETE("/admin-api/iscs/user-characteristic/deleteUserCharacteristicList")
    suspend fun deleteUserCharacteristic(
        @QueryMap params: MutableMap<String, Any>,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<Boolean>

    /**
     * 上传用户特征
     */
    @Multipart
    @POST("/admin-api/iscs/user-characteristic/insertUserFace")
    suspend fun uploadUserFace(
        @Query("userName") username: String,
        @Part part: MultipartBody.Part,
        @HeaderMap headers: Map<String, String> = ApiRequest.getUserHeaders()
    ): Response<UserCharacteristic>

}