import {z} from 'zod' export type GetApiV1CrmMetricsPenaltiesArgs = {created_at__date__gte?: string | undefined, created_at__date__lte?: string | undefined, created_by?: number | undefined, created_by__in?: Array | undefined, end_at: string, ordering?: string | undefined, page?: number | undefined, pageSize?: number | undefined, payment_status?: (0 | 1 | 2) | undefined, request__client?: number | undefined, request__client__in?: Array | undefined, request__rental_point?: number | undefined, request__rental_point__in?: Array | undefined, search?: string | undefined, start_at: string, type?: (0 | 1) | undefined, type__in?: Array | undefined}; export type GetApiV1CrmMetricsPenaltiesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const type978Enum = z.union([z.literal(0), z.literal(1)]); export const type433Enum = z.union([z.literal(0), z.literal(1)]); export const baseClient = z.object({id: z.number().int(), name: z.string().max(512), type: type433Enum.optional(), avatar: z.string().nullable().optional(), agreement_id: z.string().nullable(), signed: z.boolean().optional(), sign_date: z.string().nullable().optional(), sign_expires: z.string().nullable().optional(), phone: z.string().max(32), email: z.string().max(254).nullable().optional(), legal_type: z.union([z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]), z.unknown()]).nullable().optional(), extra: z.unknown()}); export const penaltyMetrics = z.object({id: z.number().int(), request: z.number().int(), request_status: z.number().int(), payment_status: z.number().int(), request_inventory: z.number().int().nullable().optional(), amount: z.string().optional(), reason: z.string().max(512).nullable().optional(), type: type978Enum.optional(), created_by: z.number().int().nullable().optional(), inventory_id: z.number().int(), inventory_name: z.string(), inventory_unique_id: z.string(), created_at: z.string(), client: baseClient, paid_amount: z.string(), pending_amount: z.string()}); export const paginatedPenaltyMetricsList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(penaltyMetrics)}); 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/crm/metrics/penalties/ */ export const getApiV1CrmMetricsPenalties = async (args: GetApiV1CrmMetricsPenaltiesArgs, options?: GetApiV1CrmMetricsPenaltiesOptions) => { const {baseUrl = "https://api.yume.cloud", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.created_at__date__gte != null) query.append("created_at__date__gte", String(args.created_at__date__gte)) if (args.created_at__date__lte != null) query.append("created_at__date__lte", String(args.created_at__date__lte)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.created_by__in != null) query.append("created_by__in", args.created_by__in.join(',')) if (args.end_at != null) query.append("end_at", String(args.end_at)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.payment_status != null) query.append("payment_status", String(args.payment_status)) if (args.request__client != null) query.append("request__client", String(args.request__client)) if (args.request__client__in != null) query.append("request__client__in", args.request__client__in.join(',')) if (args.request__rental_point != null) query.append("request__rental_point", String(args.request__rental_point)) if (args.request__rental_point__in != null) query.append("request__rental_point__in", args.request__rental_point__in.join(',')) if (args.search != null) query.append("search", String(args.search)) if (args.start_at != null) query.append("start_at", String(args.start_at)) if (args.type != null) query.append("type", String(args.type)) if (args.type__in != null) query.append("type__in", args.type__in.join(',')) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/metrics/penalties/${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(paginatedPenaltyMetricsList, await res.json()) };