import { invoke } from "@tauri-apps/api/core";
import { z } from "zod";
import type { Claim, ClaimCheck } from "@/lib/types";
import { ClaimSchema, ClaimCheckSchema } from "@/lib/schemas";

export async function extractClaims(text: string): Promise<Claim[]> {
  const result = await invoke<Claim[]>("extract_claims", { text });
  return z.array(ClaimSchema).parse(result);
}

export async function checkClaims(claims: Claim[]): Promise<ClaimCheck[]> {
  const result = await invoke<ClaimCheck[]>("check_claims", { claims });
  return z.array(ClaimCheckSchema).parse(result);
}

export async function saveClaims(claims: Claim[]): Promise<number> {
  const result = await invoke<number>("save_claims", { claims });
  return z.number().nonnegative().parse(result);
}

export async function getClaimCount(): Promise<number> {
  const result = await invoke<number>("get_claim_count");
  return z.number().nonnegative().parse(result);
}
