import type { QuoteItem } from "@/modules/providers/quote-provider";
import { assertRPAContext } from "@/workers/rpa/kernel/context-validator";
import type { RPAContext } from "@/workers/rpa/kernel/context";
import { runQuoteCapturePipeline } from "@/workers/rpa/quote-capture";
import type { QuoteSubmitOptions } from "@/workers/rpa/quote-capture/types";
import {
  validateQuoteSchema,
  normalizeQuoteItems,
} from "@/workers/rpa/quote-capture/quote-schema-validator";
export {
  normalizeQuote,
  resolveRatesFromBody,
  type CanonicalQuote,
} from "@/workers/rpa/quote-capture/quote-normalize";

/** @deprecated 使用 validateQuoteSchema */
export function validateResult(items: QuoteItem[]): void {
  validateQuoteSchema(items);
}

/** Kernel 报价：Network-First capture + normalize + contract + schema */
export async function scrapeQuotesStep(
  ctx: RPAContext,
  options?: QuoteSubmitOptions,
): Promise<QuoteItem[]> {
  assertRPAContext(ctx, "scrapeQuotesStep");
  const { items } = await runQuoteCapturePipeline(ctx.page, options);
  return items;
}

export { normalizeQuoteItems, validateQuoteSchema };
