import request from '@/utils/http'
import { Project } from '@/enums/api'
import {
  TaskListResParams,
  TaskListReqParams,
  AddTaskReqParams,
  AddTaskResParams,
  ModifyTaskReqParams,
  TaskDetailResParams,
  PlanDetailReqParams,
  PlanDetailResParams,
  RemoveTaskReqParams,
  SortTaskReqParams,
  CancelTaskReqParams,
  CancelTaskResParams,
  TaskDetailReqParams,
  TaskLogsReqParams,
  GetTaskFlowsResParams,
  SetTaskFlowsReqParams,
  GetPlanLogsReqParams,
  GetPlanLogsResParams
} from '@/types/plan-task'

/**
 * 获取计划任务列表
 * @param params TaskListReqParams
 */
export const getPlanTaskList = (params: TaskListReqParams) => {
  return request.post<TaskListResParams>(
    Project.PROJECT_PLAN_TASK_LIST,
    params
  )
}

/**
 * 添加计划任务信息
 * @param params AddTaskReqParams
 * @returns
 */
export const addPlanTask = (params: AddTaskReqParams) => {
  return request.post<AddTaskResParams>(
    Project.PROJECT_PLAN_TASK_ADD,
    params
  )
}

/**
 * 获取计划详情
 * @param params PlanDetailReqParams
 * @returns
 */
export const getPlanDetail = (params: PlanDetailReqParams) => {
  return request.post<PlanDetailResParams>(
    Project.PROJECT_PLAN_DETAIL,
    params
  )
}

/**
 * 修改计划任务信息
 * @param params ModifyTaskReqParams
 * @returns
 */
export const modifyPlanTask = (params: ModifyTaskReqParams) => {
  return request.post<BaseResParams>(
    Project.PROJECT_PLAN_TASK_MODIFY,
    params
  )
}

/**
 * 删除计划任务信息
 * @param id 计划任务编号
 * @returns
 */
export const removePlanTask = (params: RemoveTaskReqParams) => {
  return request.post<BaseResParams>(
    Project.PROJECT_PLAN_TASK_REMOVE,
    params
  )
}

/**
 * 调整任务项顺序
 * @param params SortTaskReqParams
 * @returns
 */
export const sortPlanTask = (params: SortTaskReqParams) => {
  return request.post<BaseResParams>(
    Project.PROJECT_PLAN_TASK_SORT,
    params
  )
}

/**
 * 中止任务项
 * @param params CancelTaskReqParams
 * @returns
 */
export const cancelPlanTask = (params: CancelTaskReqParams) => {
  return request.post<CancelTaskResParams>(
    Project.PROJECT_PLAN_TASK_CANCEL,
    params
  )
}

/**
 * 获取计划任务详情
 * @param params TaskDetailReqParams
 * @returns
 */
export const getPlanTaskDetail = (params: TaskDetailReqParams) => {
  return request.post<TaskDetailResParams>(
    Project.PROJECT_PLAN_TASK_DETAIL,
    params
  )
}

/**
 * 获取项目计划中某个任务的执行动态，即日志。
 * @param params TaskLogsReqParams
 * @returns
 */
export const getPlanTaskLogs = (params: TaskLogsReqParams) => {
  return request.post<TaskLogsReqParams>(
    Project.PROJECT_PLAN_TASK_LOGS,
    params
  )
}

/**
 * 获取项目计划中某个任务的执行动态，即日志。
 * @param params TaskLogsReqParams
 * @returns
 */
export const setPlanProgress = (params: {
  task_id: string
  progress: number
}) => {
  return request.post<BaseResParams>(
    Project.PROJECT_PLAN_SET_PROGRESS,
    params
  )
}

/**
 * 获取计划审核流程列表
 * @param params
 * @returns
 */
export const getPlanCheckFlow = (params: {
  draft: boolean
  task_id: string
}) => {
  return request.post<GetTaskFlowsResParams>(
    Project.PROJECT_PLAN_GET_CHECK_FLOW,
    params
  )
}

/**
 * 设置计划审核流程列表
 * @param params
 * @returns
 */
export const setPlanCheckFlow = (params: SetTaskFlowsReqParams) => {
  return request.post<BaseResParams>(
    Project.PROJECT_PLAN_SET_CHECK_FLOW,
    params
  )
}

/**
 * 获取任务动态
 * @param params
 * @returns
 */
export const getPlanLogs = (params: GetPlanLogsReqParams) => {
  return request.post<GetPlanLogsResParams>(
    Project.PROJECT_PLAN_LOGS,
    params
  )
}
