import {z} from 'zod' export type GetApiAgencyAgencyIdCandidateCandidateIdPositionHeldArgs = {page?: number | undefined, items_per_page?: number | undefined, job_family_id?: string | undefined, job_title_id?: string | undefined, status?: string | undefined, work_suggestion_status?: ('active' | 'inactive') | undefined, sortBy?: (Array<'overall_duration' | '-overall_duration' | 'work_suggestion_status' | '-work_suggestion_status'>) | undefined}; export type GetApiAgencyAgencyIdCandidateCandidateIdPositionHeldOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, agencyCandidate?: {username: string, password: string} | undefined, pathContextValidator?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const statesDef = z.object({status: z.string(), total_time: z.number().int(), current: z.boolean(), last_end_date: z.string()}); export const employmentPositionHeldResponseDef = z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), candidate_id: z.string(), job_family_id: z.string(), job_family_name: z.string(), job_title_id: z.string(), job_title_name: z.string(), last_computed_at: z.string(), overall_duration: z.number().int(), states: z.array(statesDef), work_suggestion_status: z.string(), work_history_ids: z.array(z.string()).optional()}); export const getApiAgencyAgencyIdCandidateCandidateIdPositionHeldResponse = z.array(employmentPositionHeldResponseDef); 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 }; /** * Retrieves a list of employment position held for a specific agency candidate * * GET /agency/{agency_id}/candidate/{candidate_id}/position-held */ export const getApiAgencyAgencyIdCandidateCandidateIdPositionHeld = async (args: GetApiAgencyAgencyIdCandidateCandidateIdPositionHeldArgs, options?: GetApiAgencyAgencyIdCandidateCandidateIdPositionHeldOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshift, agencyCandidate, pathContextValidator} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.items_per_page != null) query.append("items_per_page", String(args.items_per_page)) if (args.job_family_id != null) query.append("job_family_id", String(args.job_family_id)) if (args.job_title_id != null) query.append("job_title_id", String(args.job_title_id)) if (args.status != null) query.append("status", String(args.status)) if (args.work_suggestion_status != null) query.append("work_suggestion_status", String(args.work_suggestion_status)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) if (agencyCandidate !== undefined) headers.set('authorization', `Basic ${btoa(`${agencyCandidate.username}:${agencyCandidate.password}`)}`) if (pathContextValidator !== undefined) headers.set('authorization', `Basic ${btoa(`${pathContextValidator.username}:${pathContextValidator.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/agency/${encodeURIComponent(String(args.agency_id))}/candidate/${encodeURIComponent(String(args.candidate_id))}/position-held${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiAgencyAgencyIdCandidateCandidateIdPositionHeldResponse, await res.json()) };