import type { Page } from "playwright";
import { resolveRPAContext } from "@/workers/rpa/kernel/context";

export {
  isCargoStateReady,
  type CargoUiPhase,
  type CargoFieldSnapshot,
  type CargoBlockedField,
  type CargoStateEvidence,
  type CargoStateProbe,
} from "@/workers/rpa/kernel/state-engine";

/** @deprecated 使用 ctx.state.settleAddressEditing() */
export async function settleAddressEditingState(page: Page): Promise<void> {
  const ctx = resolveRPAContext(page);
  await ctx.state.settleAddressEditing();
}

/** @deprecated 使用 ctx.state.triggerCargoSection() */
export async function triggerCargoSectionState(page: Page): Promise<void> {
  const ctx = resolveRPAContext(page);
  await ctx.state.triggerCargoSection();
}

/** @deprecated 使用 ctx.state.probeCargo() */
export async function probeCargoUiState(page: Page) {
  const ctx = resolveRPAContext(page);
  return ctx.state.probeCargo();
}

/** @deprecated 使用 ctx.state.waitCargoInteractive() */
export async function waitForCargoInteractiveState(page: Page): Promise<void> {
  const ctx = resolveRPAContext(page);
  await ctx.state.waitCargoInteractive();
}

/** @deprecated 使用 ctx.state.fillCargoField() */
export async function fillMountedCargoField(
  page: Page,
  fieldReSource: string,
  value: string,
): Promise<boolean> {
  const ctx = resolveRPAContext(page);
  return ctx.state.fillCargoField(fieldReSource, value);
}

/** @deprecated 使用 ctx.state.assertCargoReady() */
export async function assertCargoStateReady(page: Page) {
  const ctx = resolveRPAContext(page);
  return ctx.state.assertCargoReady();
}
