import {z} from 'zod' export type Table = 0 | 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72; export type ViewType = 0 | 1; export type GetApiV1ReportUserGroupAvailabilityArgs = {FromDate: string, ToDate: string, LinkedTable?: Table | undefined, GroupIds?: string | undefined, ViewType?: ViewType | undefined, Page?: number | undefined, ItemsPerPage?: number | undefined, ReturnTotalItems?: boolean | undefined}; export type GetApiV1ReportUserGroupAvailabilityOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const reportUserGroupAvailabilityModel = z.object({groupId: z.number().int().optional(), userCount: z.number().int().optional(), dealUnavailableCount: z.number().int().optional(), ticketUnavailableCount: z.number().int().optional(), chatUnavailableCount: z.number().int().optional(), callUnavailableCount: z.number().int().optional()}); export const reportUserGroupAvailabilityModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(reportUserGroupAvailabilityModel).nullable().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 }; /** * GET /v1/report/user/group/availability * * Also accepts auth: API Key */ export const getApiV1ReportUserGroupAvailability = async (args: GetApiV1ReportUserGroupAvailabilityArgs, options: GetApiV1ReportUserGroupAvailabilityOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.FromDate != null) query.append("FromDate", String(args.FromDate)) if (args.ToDate != null) query.append("ToDate", String(args.ToDate)) if (args.LinkedTable != null) query.append("LinkedTable", String(args.LinkedTable)) if (args.GroupIds != null) query.append("GroupIds", String(args.GroupIds)) if (args.ViewType != null) query.append("ViewType", String(args.ViewType)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.ItemsPerPage != null) query.append("ItemsPerPage", String(args.ItemsPerPage)) if (args.ReturnTotalItems != null) query.append("ReturnTotalItems", String(args.ReturnTotalItems)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/report/user/group/availability${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(reportUserGroupAvailabilityModelQueryResult, await res.json()) };