import {z} from 'zod' export type GetApiFeedbackResponsesExternalReviewRepliesArgs = {user?: string | undefined, deleted?: number | undefined, page?: number | undefined, limit?: number | undefined, _select?: string | undefined, status?: ('pending-approval' | 'approved' | 'published' | 'rejected' | 'failed') | undefined}; export type GetApiFeedbackResponsesExternalReviewRepliesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiFeedbackResponsesExternalReviewRepliesResponse = z.object({response: z.array(z.object({_id: z.string().optional(), externalReview: z.string().optional(), generatedText: z.string().optional(), finalText: z.string().optional(), modelId: z.string().optional(), status: z.enum(["pending-approval", "approved", "published", "rejected", "failed"]).optional(), approvedBy: z.string().optional(), approvedAt: z.string().optional(), rejectedBy: z.string().optional(), rejectedAt: z.string().optional(), rejectionReason: z.string().optional(), publishedAt: z.string().optional(), publishError: z.string().optional(), pendingApprovalSince: z.string().optional(), facility: z.string().optional()})).optional(), page: z.number().int().optional(), size: z.number().int().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 external review replies * * GET /feedbackResponsesExternalReviewReplies */ export const getApiFeedbackResponsesExternalReviewReplies = async (args: GetApiFeedbackResponsesExternalReviewRepliesArgs, options?: GetApiFeedbackResponsesExternalReviewRepliesOptions) => { const {baseUrl = "https://api.lumahealth.io/api/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.user != null) query.append("user", String(args.user)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args._select != null) query.append("_select", String(args._select)) if (args.status != null) query.append("status", String(args.status)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/feedbackResponsesExternalReviewReplies${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(getApiFeedbackResponsesExternalReviewRepliesResponse, await res.json()) };