import { request } from '@/utils/request'
import { Project } from '@/enums/api'
import {
  WeekReportListResParams,
  WeekReportListReqParams,
  AddWeekReportReqParams,
  AddWeekReportResParams,
  ModifyWeekReportReqParams,
  WeekReportDetailResParams,
  WeekReportDownloadFileUrlReqParams,
  WeekReportDownloadFileUrlResParams,
  WeekReportUploadFileUrlReqParams,
  WeekReportUploadFileUrlResParams,
  CommitWeekReportReqParams,
  WithdrawWeekReportReqParams
} from '@/types/week-report'

/**
 * 获取周报列表
 * @param params WeekReportListReqParams
 */
export const getWeekReportList = (params: WeekReportListReqParams) => {
  return request.post<WeekReportListResParams>({
    url: Project.PROJECT_WEEK_REPORT_LIST,
    data: params
  })
}

/**
 * 添加周报信息
 * @param params AddWeekReportReqParams
 * @returns
 */
export const addWeekReport = (params: AddWeekReportReqParams) => {
  return request.post<AddWeekReportResParams>({
    url: Project.PROJECT_WEEK_REPORT_ADD,
    data: params
  })
}

/**
 * 修改周报信息
 * @param params ModifyWeekReportReqParams
 * @returns
 */
export const modifyWeekReport = (params: ModifyWeekReportReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_WEEK_REPORT_MODIFY,
    data: params
  })
}

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

/**
 * 获取周报概览
 * @param id 周报编号
 * @returns
 */
export const getWeekReportDetail = (id: string) => {
  return request.post<WeekReportDetailResParams>({
    url: Project.PROJECT_WEEK_REPORT_DETAIL,
    data: { id }
  })
}

/**
 * 获取上传周报附件的url。
 * @param params WeekReportUploadFileUrlResParams
 * @returns
 */
export const getUploadWeekReportFileUrl = (
  params: WeekReportUploadFileUrlReqParams
) => {
  return request.post<WeekReportUploadFileUrlResParams>({
    url: Project.PROJECT_WEEK_REPORT_UPLOAD_FILE,
    data: params
  })
}

/**
 * 获取下载周报附件的url。
 * @param params WeekReportDownloadFileUrlReqParams
 * @returns
 */
export const getDownloadWeekReportFileUrl = (
  params: WeekReportDownloadFileUrlReqParams
) => {
  return request.post<WeekReportDownloadFileUrlResParams>({
    url: Project.PROJECT_WEEK_REPORT_DOWNLOAD_FILE,
    data: params
  })
}

/**
 * 删除周报附件。
 * @param params 周报附件id
 * @returns
 */
export const removeReportFile = (id: string) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_WEEK_REPORT_REMOVE_FILE,
    data: { id }
  })
}

/**
 * 创建后的项目周报，需要提交，才进入后续流程。
 * @param params CommitWeekReportReqParams
 * @returns
 */
export const commitWeekReportFile = (params: CommitWeekReportReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_WEEK_REPORT_COMMIT,
    data: params
  })
}

/**
 * 提交后的项目周报，如还没有被审阅，可以撤回后重新修改。
 * @param params WithdrawWeekReportReqParams
 * @returns
 */
export const withdrawWeekReportFile = (params: WithdrawWeekReportReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_WEEK_REPORT_WITHDRAW,
    data: params
  })
}
