import {z} from 'zod' export type GetApiV1ReportAgentPerformanceArgs = {fromDate: string, toDate: string}; export type GetApiV1ReportAgentPerformanceOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const reportCCAgentPerformanceModel = z.object({departmentId: z.number().int().optional(), forDate: z.string().nullable().optional(), firstActivityTime: z.string().nullable().optional(), firstActivityState: z.number().int().nullable().optional(), lastActivityTime: z.string().nullable().optional(), lastActivityState: z.number().int().nullable().optional(), queueName: z.string().nullable().optional(), voipUserId: z.number().int().optional(), userName: z.string().nullable().optional(), extNumber: z.string().nullable().optional(), inboundCallCount: z.number().int().optional(), inboundMissedCallCount: z.number().int().optional(), outboundCallCount: z.number().int().optional(), outboundMissedCallCount: z.number().int().optional(), inboundCallSetupSuccessRate: z.number().optional(), outboundCallSetupSuccessRate: z.number().optional(), inboundProductivityRate: z.number().optional(), inboundCallTime: z.number().int().optional(), inboundLongestCallTime: z.number().int().optional(), inboundCallRingTime: z.number().int().optional(), inboundAvgCallTime: z.number().optional(), inboundAvgCallRingTime: z.number().int().optional(), outboundCallTime: z.number().int().optional(), outboundCallRingTime: z.number().int().optional(), outboundAvgCallTime: z.number().optional(), outboundAvgCallRingTime: z.number().optional(), activeTime: z.number().int().optional(), idleTime: z.number().int().optional(), outboundTime: z.number().int().optional(), middayTime: z.number().int().optional(), callWaitTime: z.number().int().optional()}); export const reportCCAgentPerformanceModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(reportCCAgentPerformanceModel).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/agent/performance * * Also accepts auth: API Key */ export const getApiV1ReportAgentPerformance = async (args: GetApiV1ReportAgentPerformanceArgs, options: GetApiV1ReportAgentPerformanceOptions) => { 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 (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/report/agent/performance${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(reportCCAgentPerformanceModelQueryResult, await res.json()) };