import { request } from '@/utils/request'
import { Project } from '@/enums/api'
import {
  ProjectListResParams,
  ProjectListReqParams,
  AddProjectReqParams,
  AddProjectResParams,
  ModifyProjectReqParams,
  OverviewProjectResParams,
  ProjectLogsReqParams,
  ProjectLogsResParams,
  ProjectMilestoneResParams,
  ProjectCheckersResParams,
  ProjectStatResParams
} from '@/types/project'

/**
 * 获取项目列表
 * @param params RequestProjectListParams
 */
export const getProjectList = (params: ProjectListReqParams) => {
  return request.post<ProjectListResParams>({
    url: Project.PROJECT_INFO_LIST,
    data: params
  })
}

/**
 * 添加项目信息
 * @param params
 * @returns
 */
export const addProject = (params: AddProjectReqParams) => {
  return request.post<AddProjectResParams>({
    url: Project.PROJECT_INFO_ADD,
    data: params
  })
}

/**
 * 修改项目信息
 * @param params
 * @returns
 */
export const modifyProject = (params: ModifyProjectReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_INFO_MODIFY,
    data: params
  })
}

/**
 * 删除项目信息
 * @param id 项目编号
 * @returns
 */
export const removeProject = (id: string) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_INFO_REMOVE,
    data: { id }
  })
}

/**
 * 获取项目概览
 * @param id 项目编号
 * @returns
 */
export const overviewProject = (id: string) => {
  return request.post<OverviewProjectResParams>({
    url: Project.PROJECT_INFO_OVERVIEW,
    data: { id }
  })
}

/**
 * 获取项目动态列表
 * @param params ProjectLogsReqParams
 * @returns
 */
export const getProjectLogs = (params: ProjectLogsReqParams) => {
  return request.post<ProjectLogsResParams>({
    url: Project.PROJECT_INFO_LOGS,
    data: params
  })
}

/**
 *
 * @param params
 * @returns
 */
export const getProjectMilestone = (params: { prj_id: string }) => {
  return request.post<ProjectMilestoneResParams>({
    url: Project.PROJECT_KANBAN_MILESTONE,
    data: params
  })
}

/**
 * 获取项目审核人列表
 * @param params
 * @returns
 */
export const getProjectCheckers = (params: { id: string }) => {
  return request.post<ProjectCheckersResParams>({
    url: Project.PROJECT_INFO_GET_CHECKERS,
    data: params
  })
}

/**
 * 获取项目审核人列表
 * @param params
 * @returns
 */
export const setProjectCheckers = (params: {
  id: string
  checkers: { id: string; name: string }[]
}) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_INFO_SET_CHECKERS,
    data: params
  })
}

/**
 * 获取项目统计信息
 * @returns
 */
export const getProjectStat = () => {
  return request.post<ProjectStatResParams>({
    url: Project.PROJECT_INFO_STAT,
    data: {}
  })
}
