import {z} from 'zod' export type GetApiV1CrmMetricsDiscountsArgs = {created_at__date__gte?: string | undefined, created_at__date__lte?: string | undefined, discount?: number | undefined, discount__discount_type?: (0 | 1) | undefined, discount__in?: Array | undefined, discount__type?: (0 | 1 | 2) | undefined, ordering?: string | undefined, page?: number | undefined, pageSize?: number | undefined, request__client?: number | undefined, request__client__in?: Array | undefined, request__payment_status?: (0 | 1 | 2) | undefined, request__payment_status__in?: Array | undefined, request__rent_end__date__gte?: string | undefined, request__rent_end__date__lte?: string | undefined, request__rent_start__date__gte?: string | undefined, request__rent_start__date__lte?: string | undefined, request__status?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, request__status__in?: Array | undefined, search?: string | undefined, type?: (0 | 1) | undefined}; export type GetApiV1CrmMetricsDiscountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metricsDiscount = z.object({discount: z.number().int(), discount_type: z.number().int(), discount_discount: z.number().int(), discount_discount_type: z.number().int(), count: z.number().int(), price: z.string(), price_discount: z.string()}); export const paginatedMetricsDiscountList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(metricsDiscount)}); 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/discounts/ */ export const getApiV1CrmMetricsDiscounts = async (args: GetApiV1CrmMetricsDiscountsArgs, options?: GetApiV1CrmMetricsDiscountsOptions) => { 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.discount != null) query.append("discount", String(args.discount)) if (args.discount__discount_type != null) query.append("discount__discount_type", String(args.discount__discount_type)) if (args.discount__in != null) query.append("discount__in", args.discount__in.join(',')) if (args.discount__type != null) query.append("discount__type", String(args.discount__type)) 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.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__payment_status != null) query.append("request__payment_status", String(args.request__payment_status)) if (args.request__payment_status__in != null) query.append("request__payment_status__in", args.request__payment_status__in.join(',')) if (args.request__rent_end__date__gte != null) query.append("request__rent_end__date__gte", String(args.request__rent_end__date__gte)) if (args.request__rent_end__date__lte != null) query.append("request__rent_end__date__lte", String(args.request__rent_end__date__lte)) if (args.request__rent_start__date__gte != null) query.append("request__rent_start__date__gte", String(args.request__rent_start__date__gte)) if (args.request__rent_start__date__lte != null) query.append("request__rent_start__date__lte", String(args.request__rent_start__date__lte)) if (args.request__status != null) query.append("request__status", String(args.request__status)) if (args.request__status__in != null) query.append("request__status__in", args.request__status__in.join(',')) if (args.search != null) query.append("search", String(args.search)) if (args.type != null) query.append("type", String(args.type)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/metrics/discounts/${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(paginatedMetricsDiscountList, await res.json()) };