/**
 * Flock Freight 录制/探针标准样例（PRD §14 / 官网 get-a-quote）
 */
export type FlockCanonicalPath = {
  id: string;
  title: string;
  input: FlockDemoInput;
  notes: string;
};

export type FlockDemoInput = {
  pickupDateDisplay: string;
  pickupZip: string;
  deliveryZip: string;
  palletCount: number;
  totalWeightLb: number;
  lengthIn: number;
  widthIn: number;
  heightIn: number;
};

function tomorrowMmDdYyyy(): string {
  const d = new Date();
  d.setDate(d.getDate() + 1);
  const mm = String(d.getMonth() + 1).padStart(2, "0");
  const dd = String(d.getDate()).padStart(2, "0");
  return `${mm}/${dd}/${d.getFullYear()}`;
}

export const DEFAULT_FLOCK_QUOTE_URL =
  "https://app.flockfreight.com/get-a-quote";

/** 与 embed-demo / probe 一致：CA → TX */
export const DEFAULT_FLOCK_DEMO: FlockDemoInput = {
  pickupDateDisplay: tomorrowMmDdYyyy(),
  pickupZip: "90001",
  deliveryZip: "75201",
  palletCount: 6,
  totalWeightLb: 10_000,
  lengthIn: 48,
  widthIn: 40,
  heightIn: 48,
};

export const FLOCK_CANONICAL_PATHS: FlockCanonicalPath[] = [
  {
    id: "F01-ltl-zip-quote",
    title: "ZIP 查价 → 两档结果（主路径）",
    input: DEFAULT_FLOCK_DEMO,
    notes: "填表 → Next → 看到 FlockDirect + Standard 即停；勿点 Complete your order",
  },
  {
    id: "F02-register-after-quote",
    title: "结果页 → 注册页（仅当需账号时）",
    input: DEFAULT_FLOCK_DEMO,
    notes: "若 Next 后进入 Create your free account，录姓名/公司/电话/邮箱/下拉 → Get instant quote",
  },
];

export function formatFlockRecordingChecklist(input: FlockDemoInput): string {
  return [
    "【Flock 人工录制清单】",
    `1. 取货日期 Pickup Date: ${input.pickupDateDisplay}`,
    `2. 取件 ZIP Pickup zip code: ${input.pickupZip}`,
    `3. 投递 ZIP Delivery zip code: ${input.deliveryZip}`,
    `4. 托盘数 Pallet Quantity: ${input.palletCount}（4–20）`,
    `5. 总重 Total Shipping Weight (lbs): ${input.totalWeightLb}`,
    `6. 尺寸 L×W×H (in): ${input.lengthIn} × ${input.widthIn} × ${input.heightIn}`,
    "7. 点击 Next / 下一个",
    "8. 等待结果页 Explore your custom quote options（两档价格）",
    "9. 若出现 Create your free account：填测试账号后点 Get instant quote",
    "10. 录制结束：不要点 Complete your order（下单边界）",
    "",
    "产出: .rpa/recordings/flock-<时间戳>.js",
    "会话: .rpa/flock-storage.json",
  ].join("\n");
}
