import { api } from '../api/client'
import type { CopyMissionData } from '../types/copyMission'

export type AudienceSamplePatchStatus = '' | 'pinned' | 'excluded'

export function copyMissionAudienceSamplePath(
  personaId: string,
  missionId: string,
  username: string,
): string {
  const user = encodeURIComponent(username.replace(/^@/, ''))
  return `/api/v1/personas/${encodeURIComponent(personaId)}/copy-missions/${encodeURIComponent(missionId)}/audience-samples/${user}`
}

export async function patchCopyMissionAudienceSample(
  personaId: string,
  missionId: string,
  username: string,
  status: AudienceSamplePatchStatus,
): Promise<CopyMissionData> {
  return api.patch<CopyMissionData>(
    copyMissionAudienceSamplePath(personaId, missionId, username),
    { status },
    { auth: true },
  )
}