import {z} from 'zod' export type GetApiSettingsTaxTablesIdArgs = {Authorization: string, SiteId: number, id: number}; export type GetApiSettingsTaxTablesIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const mindbodyRestApiCommonModelsSiteTaxTable = z.object({Id: z.number().int().optional(), Tax1: z.number().optional(), Tax2: z.number().optional(), Tax3: z.number().optional(), Tax4: z.number().optional(), Tax5: z.number().optional()}); export const getApiSettingsTaxTablesIdResponse = z.array(mindbodyRestApiCommonModelsSiteTaxTable); 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 }; /** * List of tax tables. Every location may have up to a maximum of 5 taxes. Tax values are represented as decimals. * * GET /Settings/TaxTables/{id} */ export const getApiSettingsTaxTablesId = async (args: GetApiSettingsTaxTablesIdArgs, options?: GetApiSettingsTaxTablesIdOptions) => { const {baseUrl = "https://api.mindbodyonline.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.SiteId != null) headers.set("SiteId", String(args.SiteId)) const url = `${baseUrl.replace(/\/+$/, '')}/Settings/TaxTables/${encodeURIComponent(String(args.id))}${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(getApiSettingsTaxTablesIdResponse, await res.json()) };