import {z} from 'zod' export type QPilotCoreModelsQuickLinkStatusType = 'Disabled' | 'Enabled' | 'Deleted'; export type QPilotCoreModelsQuickLinkActionType = 'Resume' | 'Pause' | 'ProcessNow' | 'Reactivate'; export type GetApiSitesSiteIdQuicklinksArgs = {siteId: number, statuses?: Array | undefined, actionTypes?: Array | undefined, search?: string | undefined, page?: number | undefined, pageSize?: number | undefined, orderBy?: string | undefined, order?: string | undefined}; export type GetApiSitesSiteIdQuicklinksOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const qPilotCoreModelsQuickLinkActionType = z.enum(["Resume", "Pause", "ProcessNow", "Reactivate"]); export const qPilotCoreModelsQuickLinkStatusType = z.enum(["Disabled", "Enabled", "Deleted"]); export const qPilotCoreModelsQuickLinkUsageLimitType = z.enum(["SingleUse", "LimitedUse", "Unlimited"]); export const qPilotCoreModelsDtoQuickLinksQuickLinkListItemDto = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), slug: z.string().nullable().optional(), actionType: qPilotCoreModelsQuickLinkActionType.optional(), status: qPilotCoreModelsQuickLinkStatusType.optional(), usageLimitType: qPilotCoreModelsQuickLinkUsageLimitType.optional(), maxUses: z.number().int().nullable().optional(), currentUsageCount: z.number().int().optional(), requiresLogin: z.boolean().optional(), createdUtc: z.string().optional(), updatedUtc: z.string().optional(), expiredUtc: z.string().nullable().optional(), templateUrl: z.string().nullable().optional()}); export const qPilotCoreModelsPagedResultQuickLinkListItemDto = z.object({items: z.array(qPilotCoreModelsDtoQuickLinksQuickLinkListItemDto).nullable().optional(), totalCount: z.number().int().optional(), totalPages: 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 }; /** * Retrieves a paginated list of QuickLinks for a specific site with optional filtering, search, and sorting. * * GET /Sites/{siteId}/Quicklinks */ export const getApiSitesSiteIdQuicklinks = async (args: GetApiSitesSiteIdQuicklinksArgs, options?: GetApiSitesSiteIdQuicklinksOptions) => { const {baseUrl = "https://api.qpilot.cloud", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.statuses ?? []) query.append("statuses", String(item)) for (const item of args.actionTypes ?? []) query.append("actionTypes", String(item)) if (args.search != null) query.append("search", String(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.order != null) query.append("order", String(args.order)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/Sites/${encodeURIComponent(String(args.siteId))}/Quicklinks${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(qPilotCoreModelsPagedResultQuickLinkListItemDto, await res.json()) };