import { createHash } from "node:crypto";

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

import { registrationNotice } from "../../packages/shared-contracts/src/index.js";

describe("TDD-WP1-NOTICE-001-registration-consent", () => {
  it("freezes a versioned and hash-verifiable registration notice", () => {
    expect(registrationNotice.version).toMatch(/^p0a-registration-notice-v[1-9][0-9]*$/);
    expect(registrationNotice.effectiveAt).toMatch(/^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/);
    expect(registrationNotice.sections.length).toBeGreaterThanOrEqual(5);
    expect(
      createHash("sha256").update(registrationNotice.content, "utf8").digest("hex"),
    ).toBe(registrationNotice.contentSha256);
  });

  it.each([
    "AI 网关",
    "Resend",
    "高德",
    "DYN004",
    "Windows",
    "文件系统权限",
    "应用层加密",
    "云备份",
    "LocalDataRoot",
    "超级管理员",
    "账号注销",
    "180 天",
    "不自动备份",
    "不会迁移到正式系统",
  ])("contains the frozen topic %s", (topic) => {
    expect(registrationNotice.content).toContain(topic);
  });
});
