import {z} from 'zod' export type PanchaPakshiInput = {date: string, timezoneOffset?: (number | null) | undefined, timezone?: string | undefined, latitude: number, longitude: number, ayanamsaId?: (number | null) | undefined, ayanamsa?: ('fagan-bradley' | 'lahiri' | 'de-luce' | 'raman' | 'krishnamurti' | 'kp' | 'yukteshwar' | 'jn-bhasin' | 'true-citra' | 'djwhal-khul') | undefined, birth?: ({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} | {[key: string]: unknown}) | undefined, janmaNakshatra?: number | undefined, birthPaksha?: ('shukla' | 'krishna') | undefined, bird?: ('vulture' | 'owl' | 'crow' | 'cock' | 'peacock') | undefined} | {[key: string]: unknown}; export type CreateApiVedicPanchangPanchaPakshiArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: PanchaPakshiInput}; export type CreateApiVedicPanchangPanchaPakshiOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicPanchangPanchaPakshiResponse = z.object({ok: z.boolean().optional(), data: z.object({method: z.string().nullable().optional(), date: z.string().nullable().optional(), weekday: z.number().nullable().optional(), paksha: z.string().nullable().optional(), sunrise: z.string().nullable().optional(), sunset: z.string().nullable().optional(), bird: z.object({key: z.string().nullable().optional(), tamil: z.string().nullable().optional(), sanskrit: z.string().nullable().optional(), from: z.string().nullable().optional()}).nullable().optional(), activities: z.object({ruling: z.object({tamil: z.string().nullable().optional(), strength: z.number().nullable().optional(), quality: z.string().nullable().optional()}).nullable().optional(), eating: z.object({tamil: z.string().nullable().optional(), strength: z.number().nullable().optional(), quality: z.string().nullable().optional()}).nullable().optional(), walking: z.object({tamil: z.string().nullable().optional(), strength: z.number().nullable().optional(), quality: z.string().nullable().optional()}).nullable().optional(), sleeping: z.object({tamil: z.string().nullable().optional(), strength: z.number().nullable().optional(), quality: z.string().nullable().optional()}).nullable().optional(), dying: z.object({tamil: z.string().nullable().optional(), strength: z.number().nullable().optional(), quality: z.string().nullable().optional()}).nullable().optional()}).nullable().optional(), yamas: z.array(z.object({index: z.number().nullable().optional(), part: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), activities: z.object({vulture: z.string().nullable().optional(), cock: z.string().nullable().optional(), owl: z.string().nullable().optional(), peacock: z.string().nullable().optional(), crow: z.string().nullable().optional()}).nullable().optional(), activity: z.string().nullable().optional(), subPeriods: z.array(z.object({bird: z.string().nullable().optional(), activity: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional()}).nullable()).nullable().optional()}).nullable()).nullable().optional(), source: z.string().nullable().optional(), basis: 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 }; /** * Panchang: Pancha Pakshi (five birds) * * POST /vedic/panchang/pancha-pakshi */ export const createApiVedicPanchangPanchaPakshi = async (args: CreateApiVedicPanchangPanchaPakshiArgs, options?: CreateApiVedicPanchangPanchaPakshiOptions) => { 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/panchang/pancha-pakshi${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(createApiVedicPanchangPanchaPakshiResponse, await res.json()) };