import { request } from '@/utils/request'
import { Project } from '@/enums/api'
import {
  ContractListResParams,
  ContractListReqParams,
  AddContractReqParams,
  AddContractResParams,
  ModifyContractReqParams,
  ContractDetailResParams,
  ContractDownloadDocUrlReqParams,
  ContractDownloadDocUrlResParams,
  ContractUploadDocUrlReqParams,
  ContractUploadDocUrlResParams,
  RemoveContractDocUrlReqParams,
  ContractStatResParams
} from '@/types/contract'

/**
 * 获取合同列表
 * @param params ContractListReqParams
 */
export const getContractList = (params: ContractListReqParams) => {
  return request.post<ContractListResParams>({
    url: Project.PROJECT_CONTRACT_LIST,
    data: params
  })
}

/**
 * 添加合同信息
 * @param params AddContractReqParams
 * @returns
 */
export const addContract = (params: AddContractReqParams) => {
  return request.post<AddContractResParams>({
    url: Project.PROJECT_CONTRACT_ADD,
    data: params
  })
}

/**
 * 修改合同信息
 * @param params ModifyContractReqParams
 * @returns
 */
export const modifyContract = (params: ModifyContractReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_CONTRACT_MODIFY,
    data: params
  })
}

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

/**
 * 获取合同概览
 * @param id 合同编号
 * @returns
 */
export const getContractDetail = (id: string) => {
  return request.post<ContractDetailResParams>({
    url: Project.PROJECT_CONTRACT_DETAIL,
    data: { id }
  })
}

/**
 * 获取上传合同附件的url。
 * @param params ContractUploadDocUrlResParams
 * @returns
 */
export const getUploadContractFileUrl = (
  params: ContractUploadDocUrlReqParams
) => {
  return request.post<ContractUploadDocUrlResParams>({
    url: Project.PROJECT_CONTRACT_UPLOAD_DOC,
    data: params
  })
}

/**
 * 获取下载合同附件的url。
 * @param params ContractDownloadDocUrlReqParams
 * @returns
 */
export const getDownloadContractFileUrl = (
  params: ContractDownloadDocUrlReqParams
) => {
  return request.post<ContractDownloadDocUrlResParams>({
    url: Project.PROJECT_CONTRACT_DOWNLOAD_DOC,
    data: params
  })
}

/**
 * 用于删除已上传的合同附件。已归档的附件不允许修改。
 * @param params
 * @returns
 */
export const removeContractFile = (params: RemoveContractDocUrlReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_CONTRACT_REMOVE_DOC,
    data: params
  })
}

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