import {z} from 'zod' export type CalendarMonthsInput = {year: number, latitude: number | null, longitude: number | null, timezone?: string | undefined, timezoneOffset?: (number | null) | undefined, ayanamsaId?: (number | null) | undefined, ayanamsa?: ('fagan-bradley' | 'lahiri' | 'de-luce' | 'raman' | 'krishnamurti' | 'kp' | 'yukteshwar' | 'jn-bhasin' | 'true-citra' | 'djwhal-khul') | undefined}; export type CreateApiVedicCalendarMonthsArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: CalendarMonthsInput}; export type CreateApiVedicCalendarMonthsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicCalendarMonthsResponse = z.object({ok: z.boolean().optional(), data: z.object({year: z.number().nullable().optional(), place: z.object({latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), timezone: z.string().nullable().optional(), timezoneOffset: z.unknown(), ayanamsaId: z.number().nullable().optional()}).nullable().optional(), months: z.array(z.object({name: z.string().nullable().optional(), index: z.number().nullable().optional(), adhika: z.boolean().nullable().optional(), kshayaOf: z.unknown(), label: z.string().nullable().optional(), newMoon: z.string().nullable().optional(), fullMoon: z.string().nullable().optional(), nextNewMoon: z.string().nullable().optional(), sunSignAtNewMoon: z.string().nullable().optional(), purnimanta: z.object({shuklaPaksha: z.string().nullable().optional(), krishnaPaksha: z.string().nullable().optional()}).nullable().optional()}).nullable()).nullable().optional(), adhika: z.array(z.string().nullable()).nullable().optional(), kshaya: z.array(z.unknown()).nullable().optional(), eras: z.object({shaka: z.object({from: z.string().nullable().optional(), number: z.number().nullable().optional(), note: z.string().nullable().optional()}).nullable().optional(), vikramChaitradi: z.object({from: z.string().nullable().optional(), number: z.number().nullable().optional(), note: z.string().nullable().optional()}).nullable().optional(), vikramKartikadi: z.object({from: z.string().nullable().optional(), number: z.number().nullable().optional(), note: z.string().nullable().optional()}).nullable().optional(), samvatsara: z.object({name: z.string().nullable().optional(), note: z.string().nullable().optional()}).nullable().optional()}).nullable().optional(), sankrantis: z.array(z.object({sign: z.string().nullable().optional(), at: z.string().nullable().optional()}).nullable()).nullable().optional(), rule: z.string().nullable().optional()}).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 }; /** * Hindu calendar: lunar months, adhika and kshaya, eras * * POST /vedic/calendar/months */ export const createApiVedicCalendarMonths = async (args: CreateApiVedicCalendarMonthsArgs, options?: CreateApiVedicCalendarMonthsOptions) => { const {baseUrl = "https://api.astroway.info/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.fields != null) query.append("fields", String(args.fields)) if (args.precision != null) query.append("precision", String(args.precision)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/vedic/calendar/months${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiVedicCalendarMonthsResponse, await res.json()) };