import {z} from 'zod' export type RequirementObjectTypeEnumParameter = 'employee' | 'employer' | 'associated_person'; export type GetApiGroupQuoteIntentsGroupQuoteIntentIdRequirementsArgs = {group_quote_intent_id: string, object_type?: RequirementObjectTypeEnumParameter | undefined, object_id?: string | undefined, page?: number | undefined, page_size?: number | undefined}; export type GetApiGroupQuoteIntentsGroupQuoteIntentIdRequirementsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const requirementObjectType = z.enum(["employee", "employer", "associated_person"]); export const requirementType = z.enum(["group_quote_intent", "group_policy_intent", "dependent_management_intent", "policy_amendment_intent", "enrolment_intent"]); export const groupQuoteIntentRequirementResponse = z.object({id: z.string(), object_type: requirementObjectType, object_id: z.string(), is_fulfilled: z.boolean(), requirement_type: requirementType, object: z.string().optional()}); export const groupQuoteIntentRequirementResponsePagedList = z.object({items: z.array(groupQuoteIntentRequirementResponse), page: z.number().int(), page_size: z.number().int(), total_count: z.number().int(), has_next_page: z.boolean().optional(), has_previous_page: z.boolean().optional()}); 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 }; /** * List requirements for a group quote intent * * GET /group_quote_intents/{group_quote_intent_id}/requirements */ export const getApiGroupQuoteIntentsGroupQuoteIntentIdRequirements = async (args: GetApiGroupQuoteIntentsGroupQuoteIntentIdRequirementsArgs, options?: GetApiGroupQuoteIntentsGroupQuoteIntentIdRequirementsOptions) => { const {baseUrl = "https://test.api.kota.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.object_type != null) query.append("object_type", String(args.object_type)) if (args.object_id != null) query.append("object_id", String(args.object_id)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/group_quote_intents/${encodeURIComponent(String(args.group_quote_intent_id))}/requirements${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(groupQuoteIntentRequirementResponsePagedList, await res.json()) };