import {z} from 'zod' export type GetApiApiV1ImprovementScalesImprovementScaleIdArgs = {ImprovementScaleId: number, Fields?: string | undefined}; export type GetApiApiV1ImprovementScalesImprovementScaleIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const improvementScaleType = z.enum(["Standard", "Generational"]); export const getImprovementScaleResponseV1 = z.object({id: z.number().int().optional(), modelId: z.number().int().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), improvementScaleType: improvementScaleType.optional(), firstCalendarYear: z.number().int().nullable().optional(), ultimateCalendarYear: z.number().int().nullable().optional(), version: z.number().int().optional()}); 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 an improvement scale. * * GET /api/v1/ImprovementScales/{ImprovementScaleId} */ export const getApiApiV1ImprovementScalesImprovementScaleId = async (args: GetApiApiV1ImprovementScalesImprovementScaleIdArgs, options: GetApiApiV1ImprovementScalesImprovementScaleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Fields != null) query.append("Fields", String(args.Fields)) if (APIToken !== undefined) headers.set('authorization', `Bearer ${APIToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/ImprovementScales/${encodeURIComponent(String(args.ImprovementScaleId))}${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(getImprovementScaleResponseV1, await res.json()) };