import {z} from 'zod' export type DashaInput = {date: string, time: string, timezoneOffset?: (number | null) | undefined, timezone?: string | undefined, latitude: number, longitude: number, houseSystem?: ('P' | 'K' | 'R' | 'C' | 'E' | 'W' | 'B' | 'M' | 'O' | 'A' | 'T' | 'V' | 'D' | 'F' | 'G' | 'H' | 'I' | 'i' | 'L' | 'N' | 'Q' | 'S' | 'U' | 'X' | 'Y') | undefined, name?: string | undefined, city?: string | undefined, zodiacType?: ('tropical' | 'sidereal') | undefined, ayanamsaId?: (number | null) | undefined, ayanamsa?: ('fagan-bradley' | 'lahiri' | 'de-luce' | 'raman' | 'krishnamurti' | 'kp' | 'yukteshwar' | 'jn-bhasin' | 'true-citra' | 'djwhal-khul') | undefined, cosmogram?: boolean | undefined, targetDate?: string | undefined, targetTime?: string | undefined, targetTzOffset?: (number | null) | undefined} | {[key: string]: unknown}; export type CreateApiVedicDashasDwadashottariAntarArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: DashaInput}; export type CreateApiVedicDashasDwadashottariAntarOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicDashasDwadashottariAntarResponse = z.object({ok: z.boolean().optional(), data: z.object({system: z.string().nullable().optional(), level: z.string().nullable().optional(), ayanamsa: z.number().nullable().optional(), moonSiderealLongitude: z.number().nullable().optional(), nakshatra: z.object({number: z.number().nullable().optional(), name: z.string().nullable().optional(), ruler: z.string().nullable().optional(), startDeg: z.number().nullable().optional(), endDeg: z.number().nullable().optional(), pada: z.number().nullable().optional()}).nullable().optional(), initial: z.object({initialPlanet: z.string().nullable().optional(), starsCounted: z.number().nullable().optional(), remainder: z.number().nullable().optional(), fullPeriodYears: z.number().nullable().optional(), elapsedYears: z.number().nullable().optional(), balanceYears: z.number().nullable().optional(), balanceFmt: z.string().nullable().optional(), pada: z.number().nullable().optional(), count: z.string().nullable().optional(), cycleYears: z.number().nullable().optional(), applicable: z.boolean().nullable().optional(), applicabilityNote: z.string().nullable().optional()}).nullable().optional(), currentMaha: z.object({planet: z.number().nullable().optional(), planetName: z.string().nullable().optional(), startJd: z.number().nullable().optional(), endJd: z.number().nullable().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), durationYears: z.number().nullable().optional()}).nullable().optional(), periods: z.array(z.object({planet: z.number().nullable().optional(), planetName: z.string().nullable().optional(), startJd: z.number().nullable().optional(), endJd: z.number().nullable().optional(), startDate: z.string().nullable().optional(), endDate: z.string().nullable().optional(), durationYears: z.number().nullable().optional()}).nullable()).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 }; /** * Dashas: Dwadashottari Antardasha * * POST /vedic/dashas/dwadashottari/antar */ export const createApiVedicDashasDwadashottariAntar = async (args: CreateApiVedicDashasDwadashottariAntarArgs, options?: CreateApiVedicDashasDwadashottariAntarOptions) => { 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/dashas/dwadashottari/antar${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(createApiVedicDashasDwadashottariAntarResponse, await res.json()) };