import {z} from 'zod' export type GetApiApiAdminReportsCommercialProcessDataArgs = {tipo_cita?: (string | null) | undefined, comercial?: (string | null) | undefined, estado?: (string | null) | undefined, fecha_inicio?: (string | null) | undefined, fecha_fin?: (string | null) | undefined, dealstage?: (string | null) | undefined, with_installation?: boolean | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiAdminReportsCommercialProcessDataOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const commercialProcessData = z.object({id: z.number().int(), contact_id: z.string(), deal_id: z.string().nullable(), email: z.string(), phone: z.string().nullable(), comercial: z.string().nullable(), teleoperadora: z.string().nullable(), estado: z.string().nullable(), fecha_visita: z.string().nullable(), fecha_de_cierre_de_visita: z.string().nullable(), fecha_previsualizacion: z.string().nullable(), fecha_prevista_instalacion: z.string().nullable(), cita_app_instalacion: z.string().nullable(), cita_app_previsualizacion: z.string().nullable(), dealstage: z.string().nullable(), firstname: z.string().nullable(), lastname: z.string().nullable(), full_name: z.string(), tipo_cita: z.string().nullable(), synced_at: z.string().nullable(), created_at: z.string().nullable()}); export const commercialProcessListResponse = z.object({data: z.array(commercialProcessData), total: z.number().int()}); 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 Commercial Process Data * * GET /api/admin/reports/commercial-process/data */ export const getApiApiAdminReportsCommercialProcessData = async (args: GetApiApiAdminReportsCommercialProcessDataArgs, options: GetApiApiAdminReportsCommercialProcessDataOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tipo_cita != null) query.append("tipo_cita", String(args.tipo_cita)) if (args.comercial != null) query.append("comercial", String(args.comercial)) if (args.estado != null) query.append("estado", String(args.estado)) if (args.fecha_inicio != null) query.append("fecha_inicio", String(args.fecha_inicio)) if (args.fecha_fin != null) query.append("fecha_fin", String(args.fecha_fin)) if (args.dealstage != null) query.append("dealstage", String(args.dealstage)) if (args.with_installation != null) query.append("with_installation", String(args.with_installation)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/admin/reports/commercial-process/data${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(commercialProcessListResponse, await res.json()) };