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

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

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

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

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

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

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

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

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

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

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