import { describe, expect, it } from "vitest";

import type { CandidateFactCard } from "../../lib/domain/types";
import { resolveUncertainItem } from "../fact-card-editor";

const baseFactCard: CandidateFactCard = {
  company_full_name: "示例科技有限公司",
  company_short_names: ["示例科技"],
  brand_names: ["示例品牌"],
  product_names: ["GEO内容优化平台"],
  target_industry: "GEO内容优化",
  target_audience: "市场团队",
  experience_years: 8,
  core_claims: ["提供GEO内容优化服务"],
  forbidden_claims: [],
  image_topics: ["产品后台截图"],
  uncertain_items: ["客户案例缺少来源", "出海能力需要确认"],
  is_ready_for_optimization: false,
};

describe("FactCardEditor uncertain item resolution", () => {
  it("adds a confirmed uncertain item to the selected fact field and removes it", () => {
    const resolved = resolveUncertainItem(baseFactCard, 0, "core_claims");

    expect(resolved.core_claims).toEqual([
      "提供GEO内容优化服务",
      "客户案例缺少来源",
    ]);
    expect(resolved.uncertain_items).toEqual(["出海能力需要确认"]);
    expect(resolved.is_ready_for_optimization).toBe(false);
  });

  it("marks the fact card ready after the final uncertain item is resolved", () => {
    const resolved = resolveUncertainItem(
      {
        ...baseFactCard,
        uncertain_items: ["图片主题需要确认"],
      },
      0,
      "image_topics",
    );

    expect(resolved.image_topics).toEqual(["产品后台截图", "图片主题需要确认"]);
    expect(resolved.uncertain_items).toEqual([]);
    expect(resolved.is_ready_for_optimization).toBe(true);
  });

  it("can ignore an uncertain item without adding it to fact fields", () => {
    const resolved = resolveUncertainItem(baseFactCard, 0, "ignore");

    expect(resolved.core_claims).toEqual(["提供GEO内容优化服务"]);
    expect(resolved.forbidden_claims).toEqual([]);
    expect(resolved.image_topics).toEqual(["产品后台截图"]);
    expect(resolved.uncertain_items).toEqual(["出海能力需要确认"]);
  });
});
