import {z} from 'zod' export type RegionalMonthsInput = {calendar: 'tamil' | 'malayalam' | 'bengali' | 'gujarati' | 'marathi', 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 CreateApiVedicCalendarRegionalMonthsArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: RegionalMonthsInput}; export type CreateApiVedicCalendarRegionalMonthsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicCalendarRegionalMonthsResponse = z.object({ok: z.boolean().optional(), data: z.object({calendar: z.string().nullable().optional(), 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(), number: z.number().nullable().optional(), sign: z.string().nullable().optional(), sankranti: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), days: z.number().nullable().optional(), year: z.object({era: z.string().nullable().optional(), number: z.unknown(), name: z.string().nullable().optional()}).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 }; /** * Regional calendar: month boundaries for a year * * POST /vedic/calendar/regional/months */ export const createApiVedicCalendarRegionalMonths = async (args: CreateApiVedicCalendarRegionalMonthsArgs, options?: CreateApiVedicCalendarRegionalMonthsOptions) => { 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/regional/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(createApiVedicCalendarRegionalMonthsResponse, await res.json()) };