import {z} from 'zod' export type GetApiSubscribersLocationCountsArgs = {'request.studioIds'?: Array | undefined, 'request.startDate'?: string | undefined, 'request.endDate'?: string | undefined}; export type GetApiSubscribersLocationCountsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiDtoModelsSubscribersLocationCountControllerStudioLocationCount = z.object({StudioId: z.number().int().optional(), LocationCountDate: z.string().optional(), LocationCount: z.number().int().optional()}); export const getApiSubscribersLocationCountsResponse = z.array(mindbodyRestApiDtoModelsSubscribersLocationCountControllerStudioLocationCount); 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 aggregated location count for specified studio IDs. * If date range is not specified, it defaults to today's date. * If endDate is not specified, it will be set to startDate vice versa. * Time part of the date range will be ignored. * * GET /Subscribers/LocationCounts */ export const getApiSubscribersLocationCounts = async (args: GetApiSubscribersLocationCountsArgs, options?: GetApiSubscribersLocationCountsOptions) => { const {baseUrl = "https://api.mindbodyonline.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['request.studioIds'] ?? []) query.append("request.studioIds", String(item)) if (args['request.startDate'] != null) query.append("request.startDate", String(args['request.startDate'])) if (args['request.endDate'] != null) query.append("request.endDate", String(args['request.endDate'])) const url = `${baseUrl.replace(/\/+$/, '')}/Subscribers/LocationCounts${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(getApiSubscribersLocationCountsResponse, await res.json()) };