import {z} from 'zod' export type PoruthamInput = {chart1: {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}, chart2: {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}, school?: ('tamil' | 'kerala') | undefined}; export type CreateApiVedicCompatibilityPoruthamArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: PoruthamInput}; export type CreateApiVedicCompatibilityPoruthamOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicCompatibilityPoruthamResponse = z.object({ok: z.boolean().optional(), data: z.object({method: z.string().nullable().optional(), school: z.string().nullable().optional(), factors: z.array(z.object({factor: z.string().nullable().optional(), verdict: z.string().nullable().optional(), pass: z.boolean().nullable().optional(), score: z.number().nullable().optional(), rule: z.string().nullable().optional(), source: z.string().nullable().optional(), basis: z.string().nullable().optional(), detail: z.object({count: z.number().nullable().optional()}).nullable().optional()}).nullable()).nullable().optional(), passed: z.number().nullable().optional(), score: z.number().nullable().optional(), max: z.number().nullable().optional(), essentialFailed: z.array(z.unknown()).nullable().optional(), verdict: z.string().nullable().optional(), verdictRule: 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 }; /** * Porutham: South Indian 10 factors * * POST /vedic/compatibility/porutham */ export const createApiVedicCompatibilityPorutham = async (args: CreateApiVedicCompatibilityPoruthamArgs, options?: CreateApiVedicCompatibilityPoruthamOptions) => { 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/compatibility/porutham${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(createApiVedicCompatibilityPoruthamResponse, await res.json()) };