import { describe, it } from "node:test";
import assert from "node:assert/strict";

import { getMessageForRound, TOTAL_ROUNDS } from "../src/chat-templates.js";

describe("chat-templates", () => {
  it("TOTAL_ROUNDS 应为 4", () => {
    assert.equal(TOTAL_ROUNDS, 4);
  });

  it("Round 1: 包含商品标题", () => {
    const msg = getMessageForRound(1, { title: "苹果17手机壳" });
    assert.ok(msg.includes("苹果17手机壳"), `消息应包含商品标题: ${msg}`);
    assert.ok(msg.includes("有现货"), `消息应询问现货: ${msg}`);
  });

  it("Round 1: 缺少 title 时 fallback 到 material_name", () => {
    const msg = getMessageForRound(1, { material_name: "钢化膜" });
    assert.ok(msg.includes("钢化膜"));
  });

  it("Round 1: 全空时 fallback 到默认文案", () => {
    const msg = getMessageForRound(1, {});
    assert.ok(msg.includes("该商品"));
  });

  it("Round 2: 包含规格和数量", () => {
    const msg = getMessageForRound(2, {
      specification: "304不锈钢 50mm",
      quantity: "500",
      unit: "件",
    });
    assert.ok(msg.includes("304不锈钢 50mm"), `消息应包含规格: ${msg}`);
    assert.ok(msg.includes("500件"), `消息应包含数量: ${msg}`);
  });

  it("Round 2: 缺少规格时 fallback", () => {
    const msg = getMessageForRound(2, { material_name: "螺丝" });
    assert.ok(msg.includes("螺丝"));
  });

  it("Round 3: 基本询价话术", () => {
    const msg = getMessageForRound(3, {});
    assert.ok(msg.includes("最低什么价格"));
    assert.ok(msg.includes("交期"));
  });

  it("Round 3: 含品牌时提及品牌", () => {
    const msg = getMessageForRound(3, { brand: "海尔" });
    assert.ok(msg.includes("海尔"));
  });

  it("Round 4: 合规询问", () => {
    const msg = getMessageForRound(4, {});
    assert.ok(msg.includes("国标") || msg.includes("国标"));
    assert.ok(msg.includes("增值税"));
  });

  it("Round 4: 含技术标准时填充", () => {
    const msg = getMessageForRound(4, { technical_standard: "GB/T 1234" });
    assert.ok(msg.includes("GB/T 1234"));
  });

  it("无效轮次抛错", () => {
    assert.throws(() => getMessageForRound(0, {}), /无效轮次/);
    assert.throws(() => getMessageForRound(5, {}), /无效轮次/);
  });
});
