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

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

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

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

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

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

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

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

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