import {z} from 'zod' export type PatchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectArgs = {projectId: string, candidateId: string, body: {rejectionType: 'by_us' | 'by_client' | 'self', rejectionReason?: ('above_budget' | 'accepted_another_offer' | 'cultural_fit' | 'did_not_attend_the_interview' | 'not_available' | 'not_qualified' | 'other' | 'overqualified' | 'reference_check_failed' | 'rejected_the_offer' | 'technical_test_failed' | 'unresponsive' | 'location' | 'rejected_by_us_or_client' | 'poor_communication' | 'no_right_to_work' | 'lacks_primary_skillset' | 'not_enough_experience' | 'doesnt_have_qualification' | 'position_was_closed' | 'went_with_another_provider' | 'went_cold' | 'too_expensive' | 'not_using_agencies' | 'not_interested' | 'not_currently_hiring' | 'no_response' | 'no_reason' | 'decided_not_to_hire' | 'null' | null) | undefined, customRejectionReasonId?: (string | null) | undefined, rejectionDetails?: (string | null) | undefined}}; export type PatchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), personId: z.string(), projectId: z.string(), statusId: z.string(), rejectionType: z.string(), rejectionReason: z.string().nullable(), customRejectionReasonId: z.string().nullable(), rejectionDetails: z.string().nullable(), rejectedAt: z.string()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Reject a candidate * * PATCH /api/v1/projects/{projectId}/candidates/{candidateId}/reject */ export const patchApiApiV1ProjectsProjectIdCandidatesCandidateIdReject = async (args: PatchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectArgs, options: PatchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectId))}/candidates/${encodeURIComponent(String(args.candidateId))}/reject${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiApiV1ProjectsProjectIdCandidatesCandidateIdRejectResponse, await res.json()) };