import { request } from '@/utils/request'
import { Project } from '@/enums/api'
import {
  WorkListReqParams,
  WorkListResParams,
  WorkDetailResParams,
  WorkSubmitReqParams,
  UploadWorkFileReqParams,
  UploadWorkFileResParams,
  WorkStatResParams,
  WorkChainReqParams,
  WorkChain
} from '@/types/work'

/**
 * 获取我的任务列表
 * @param params WorkListReqParams
 * @returns
 */
export const getWorkList = (params: WorkListReqParams) => {
  return request.post<WorkListResParams>({
    url: Project.PROJECT_WORK_LIST,
    data: params
  })
}

/**
 * 获取任务详情
 * @param id id
 * @returns
 */
export const getWorkDetail = (id: string) => {
  return request.post<WorkDetailResParams>({
    url: Project.PROJECT_WORK_DETAIL,
    data: { id }
  })
}

/**
 * 提交我的待办任务信息
 * @param parasm WorkSubmitReqParams
 * @returns
 */
export const submitWork = (params: WorkSubmitReqParams) => {
  return request.post<WorkDetailResParams>({
    url: Project.PROJECT_WORK_SUBMIT,
    data: params
  })
}

/**
 * 获取work表单提交上传文件url
 * @param params
 * @returns
 */
export const getUploadWorkFileUrl = (params: UploadWorkFileReqParams) => {
  return request.post<UploadWorkFileResParams>({
    url: Project.PROJECT_WORK_UPLOAD_FILE,
    data: params
  })
}

/**
 * 获取工作统计信息
 * @returns
 */
export const getWorkStat = () => {
  return request.post<WorkStatResParams>({
    url: Project.PROJECT_WORK_STAT,
    data: {}
  })
}

/**
 * 获取工作统计信息
 * @returns
 */
export const getWorkDoneStat = () => {
  return request.post<WorkStatResParams>({
    url: Project.PROJECT_WORK_DONE_STAT,
    data: {}
  })
}

/**
 * 获取工作统计信息
 * @returns
 */
export const getWorkUndoneStat = () => {
  return request.post<WorkStatResParams>({
    url: Project.PROJECT_WORK_UNDONE_STAT,
    data: {}
  })
}

/**
 * 获取work表单提交上传文件url
 * @param params
 * @returns
 */
export const getDownloadWorkFileUrl = (params: { id: string }) => {
  return request.post<UploadWorkFileResParams>({
    url: Project.PROJECT_WORK_DOWNLOAD_FILE,
    data: params
  })
}

// 获取我的未完成工作数量
export const getWorkUndoneCount = () => {
  return request.post<{ undone_count: number }>({
    url: Project.PROJECT_WORK_UNDONE_COUNT,
    data: {}
  })
}

/**
 * 获取工作项链
 * @param params
 * @returns
 */
export const getWorkChain = (params: WorkChainReqParams) => {
  return request.post<WorkChain[]>({
    url: Project.PROJECT_WORK_GET_CHAIN,
    data: params
  })
}
