const assert = require("assert");
const fs = require("fs");
const path = require("path");

const relationApiPath = path.resolve(
  __dirname,
  "../../src/api/ccdiStaffFmyRelation.js"
);
const assetApiPath = path.resolve(
  __dirname,
  "../../src/api/ccdiAssetInfo.js"
);

assert(fs.existsSync(relationApiPath), "未找到亲属关系 API 文件 ccdiStaffFmyRelation.js");
assert(fs.existsSync(assetApiPath), "未找到资产 API 文件 ccdiAssetInfo.js");

const relationSource = fs.readFileSync(relationApiPath, "utf8");
const assetSource = fs.readFileSync(assetApiPath, "utf8");

[
  "export function getRelation(id)",
  "export function addRelation(data)",
  "export function updateRelation(data)",
  "data: data",
].forEach((token) => {
  assert(
    relationSource.includes(token),
    `亲属关系 API 需保持聚合保存契约: ${token}`
  );
});

[
  "export function importAssetTemplate()",
  "export function importAssetData(data)",
  "export function getAssetImportStatus(taskId)",
  "export function getAssetImportFailures(taskId, pageNum, pageSize)",
  "/ccdi/assetInfo/importTemplate",
  "/ccdi/assetInfo/importData",
  "/ccdi/assetInfo/importStatus/",
  "/ccdi/assetInfo/importFailures/",
].forEach((token) => {
  assert(assetSource.includes(token), `亲属资产 API 缺少关键契约: ${token}`);
});

[
  "/ccdi/baseStaff/asset/importTemplate",
  "/ccdi/baseStaff/asset/importData",
  "/ccdi/baseStaff/asset/importStatus/",
  "/ccdi/baseStaff/asset/importFailures/",
].forEach((token) => {
  assert(!assetSource.includes(token), `亲属资产 API 不应引用员工资产接口: ${token}`);
});

console.log("staff-family-asset-api-contract test passed");
