import "dotenv/config";
import { validateProbeItems } from "../lib/rpa/probe-validation";
import { executeProbeQuote } from "../lib/rpa/run-probe";

async function main() {
  console.log("RPA_MOCK_MODE=", process.env.RPA_MOCK_MODE);

  try {
    const result = await executeProbeQuote();
    const validation = validateProbeItems(result.items);

    if (!validation.ok) {
      console.error(`[FAIL] ${validation.message}`);
      process.exitCode = 1;
      return;
    }

    console.log(
      "[PASS]",
      JSON.stringify(
        {
          sourceType: result.sourceType,
          itemCount: result.items.length,
          items: result.items.map((item) => ({
            tier: `${item.serviceLevel}/${item.rateOption}`,
            rawFreight: item.rawFreight,
            transitDays: item.transitDays,
          })),
        },
        null,
        2,
      ),
    );
  } catch (error) {
    console.error("[FAIL]", error);
    process.exitCode = 1;
  }
}

main();
