import { request } from '@/utils/request'
import { Project } from '@/enums/api'
import {
  MemberListReqParams,
  MemberListResParams,
  AddMemberReqParams,
  ApplyRemoveMemberReqParams,
  ApplyAddMemberResParams,
  ApplyAddMemberReqParams,
  ApplyRemoveMemberResParams,
  ModifyMemberReqParams,
  RemoveMemberReqParams,
  CheckMemberReqParams
} from '@/types/member'

/**
 * 获取项目组成员列表
 * @param params MemberListReqParams
 * @returns MemberListResParams
 */
export const getMemberList = (params: MemberListReqParams) => {
  return request.post<MemberListResParams>({
    url: Project.PROJECT_MEMBER_LIST,
    data: params
  })
}

/**
 * 添加项目组成员
 * @param params MemberListReqParams
 * @returns BaseResParams
 */
export const addMember = (params: AddMemberReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_MEMBER_ADD,
    data: params
  })
}

/**
 * 修改项目组成员
 * @param params ModifyMemberReqParams
 * @returns BaseResParams
 */
export const modifyMember = (params: ModifyMemberReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_MEMBER_MODIFY,
    data: params
  })
}

/**
 * 删除项目组成员
 * @param params ModifyMemberReqParams
 * @returns BaseResParams
 */
export const removeMember = (params: RemoveMemberReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_MEMBER_REMOVE,
    data: params
  })
}

/**
 * 申请添加项目组成员
 * @param params ApplyAddMemberReqParams
 * @returns ApplyAddMemberResParams
 */
export const applyAddMember = (params: ApplyAddMemberReqParams) => {
  return request.post<ApplyAddMemberResParams>({
    url: Project.PROJECT_MEMBER_APPLY_ADD,
    data: params
  })
}

/**
 * 申请删除项目组成员
 * @param params ApplyRemoveMemberReqParams
 * @returns ApplyAddMemberResParams
 */
export const applyRemoveMember = (params: ApplyRemoveMemberReqParams) => {
  return request.post<ApplyRemoveMemberResParams>({
    url: Project.PROJECT_MEMBER_APPLY_REMOVE,
    data: params
  })
}

/**
 * 申请添加或移除项目组成员后，审核是否通过。
 * @param params CheckMemberReqParams
 * @returns BaseResParams
 */
export const checkMember = (params: CheckMemberReqParams) => {
  return request.post<BaseResParams>({
    url: Project.PROJECT_MEMBER_CHECK,
    data: params
  })
}
