import {z} from 'zod' export type ChannelType = 1 | 2 | 3 | 4 | 5 | 8 | 10 | 11 | 13 | 14 | 15 | 16; export type ViewType = 0 | 1; export type GetApiV1ReportQueueAgentratingsArgs = {FromDate?: string | undefined, ToDate?: string | undefined, Channel?: ChannelType | undefined, CountryCode?: string | undefined, City?: string | undefined, Url?: string | undefined, WidgetId?: number | undefined, AssignedGroupId?: number | undefined, DepartmentId?: number | undefined, ViewType?: ViewType | undefined, Page?: number | undefined, ItemsPerPage?: number | undefined, ReturnTotalItems?: boolean | undefined}; export type GetApiV1ReportQueueAgentratingsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const reportTotalChatUserModel = z.object({userName: z.string().nullable().optional(), total: z.number().int().optional(), solved: z.number().int().optional(), totalResponseTime: z.string().nullable().optional(), totalTime: z.string().nullable().optional(), totalWorkTime: z.string().nullable().optional(), totalResponseTimeMin: z.number().int().optional(), totalTimeMin: z.number().int().optional(), totalWorkTimeMin: z.number().int().optional(), totalTimeSec: z.number().int().optional(), avgTotalResponseTimeSec: z.number().int().optional(), avgtotalTimeSec: z.number().int().optional(), avgTotalResponseTime2: z.string().nullable().optional(), avgTotalTime2: z.string().nullable().optional()}); export const reportTotalChatUserModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(reportTotalChatUserModel).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/queue/agentratings * * Also accepts auth: API Key */ export const getApiV1ReportQueueAgentratings = async (args: GetApiV1ReportQueueAgentratingsArgs, options: GetApiV1ReportQueueAgentratingsOptions) => { 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.Channel != null) query.append("Channel", String(args.Channel)) if (args.CountryCode != null) query.append("CountryCode", String(args.CountryCode)) if (args.City != null) query.append("City", String(args.City)) if (args.Url != null) query.append("Url", String(args.Url)) if (args.WidgetId != null) query.append("WidgetId", String(args.WidgetId)) if (args.AssignedGroupId != null) query.append("AssignedGroupId", String(args.AssignedGroupId)) if (args.DepartmentId != null) query.append("DepartmentId", String(args.DepartmentId)) 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/queue/agentratings${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(reportTotalChatUserModelQueryResult, await res.json()) };