import axios from './instance'
import {
  GET_MEMBER_LIST,
  ADD_MEMBER,
  DEL_MEMBER,
  UPDATE_MEBER,
  CHECK_MEMBER_PHONE
} from './constant'
import type { PageResult, PageRequest, Project } from './'

export interface Member {
  teamId: number
  userName: string
  remark: string
}

export type Members = Member[]

export const fetchMembers = (
  params: PageRequest<
    Pick<Member, 'userName'> & { projectId: Project['projectId'] }
  >
) => axios.post<PageResult<Member>>(GET_MEMBER_LIST, params)

export const deleteMember = (teamId: Member['teamId']) =>
  axios.post(DEL_MEMBER, { teamId })

export const addMember = (
  projectId: Project['projectId'],
  member: Omit<Member, 'teamId'>
) => axios.post(ADD_MEMBER, { projectId, ...member })

export const updateMember = (member: PartialPart<Member, 'userName'>) =>
  axios.post(UPDATE_MEBER, member)

export const checkMemberUserName = (userName: Member['userName']) =>
  axios.get(CHECK_MEMBER_PHONE, { params: { userName } })
