import {z} from 'zod' export type ChartInput = {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}; export type BulkMatchInput = {profile: {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}, profileRole: 'groom' | 'bride', candidates: Array<{id?: string | undefined, chart: ChartInput}>, school?: ('tamil' | 'kerala') | undefined, mangalSchool?: ('strict' | 'north' | 'south') | undefined, sortBy?: ('ashtakoot' | 'porutham') | undefined, minAshtakoot?: (number | null) | undefined}; export type CreateApiVedicCompatibilityBulkArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: BulkMatchInput}; export type CreateApiVedicCompatibilityBulkOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicCompatibilityBulkResponse = z.object({ok: z.boolean().optional(), data: z.object({method: z.string().nullable().optional(), profileRole: z.string().nullable().optional(), school: z.string().nullable().optional(), mangalSchool: z.string().nullable().optional(), sortBy: z.string().nullable().optional(), profile: z.object({star: z.number().nullable().optional(), sign: z.number().nullable().optional()}).nullable().optional(), candidates: z.number().nullable().optional(), returned: z.number().nullable().optional(), results: z.array(z.object({id: z.string().nullable().optional(), index: z.number().nullable().optional(), star: z.number().nullable().optional(), sign: z.number().nullable().optional(), ashtakoot: z.object({total: z.number().nullable().optional(), threshold: z.string().nullable().optional(), topKootas: z.array(z.object({koota: z.string().nullable().optional(), score: z.number().nullable().optional(), max: z.number().nullable().optional()}).nullable()).nullable().optional(), doshas: z.array(z.string().nullable()).nullable().optional()}).nullable().optional(), porutham: z.object({passed: z.number().nullable().optional(), max: z.number().nullable().optional(), essentialFailed: z.array(z.unknown()).nullable().optional(), verdict: z.string().nullable().optional()}).nullable().optional(), mangal: z.string().nullable().optional(), doshasUncancelled: z.array(z.unknown()).nullable().optional(), rank: z.number().nullable().optional()}).nullable()).nullable().optional(), errors: z.array(z.unknown()).nullable().optional(), credits: z.number().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 }; /** * Compatibility: bulk matching (1 against up to 100) * * POST /vedic/compatibility/bulk */ export const createApiVedicCompatibilityBulk = async (args: CreateApiVedicCompatibilityBulkArgs, options?: CreateApiVedicCompatibilityBulkOptions) => { 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/bulk${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(createApiVedicCompatibilityBulkResponse, await res.json()) };