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

const baseStaffApiPath = path.resolve(
  __dirname,
  "../../src/api/ccdiBaseStaff.js"
);
const baseStaffAssetApiPath = path.resolve(
  __dirname,
  "../../src/api/ccdiBaseStaffAsset.js"
);

assert(fs.existsSync(baseStaffApiPath), "未找到员工 API 文件 ccdiBaseStaff.js");
assert(
  fs.existsSync(baseStaffAssetApiPath),
  "未找到员工资产 API 文件 ccdiBaseStaffAsset.js"
);

const baseStaffSource = fs.readFileSync(baseStaffApiPath, "utf8");
const assetSource = fs.readFileSync(baseStaffAssetApiPath, "utf8");

[
  "export function addBaseStaff(data)",
  "export function updateBaseStaff(data)",
  "data: data",
].forEach((token) => {
  assert(
    baseStaffSource.includes(token),
    `员工 API 需保持透传聚合保存数据: ${token}`
  );
});

[
  "export function importBaseStaffAssetTemplate()",
  "export function importBaseStaffAssetData(data)",
  "export function getBaseStaffAssetImportStatus(taskId)",
  "export function getBaseStaffAssetImportFailures(taskId, pageNum, pageSize)",
  "/ccdi/baseStaff/asset/importTemplate",
  "/ccdi/baseStaff/asset/importData",
  "/ccdi/baseStaff/asset/importStatus/",
  "/ccdi/baseStaff/asset/importFailures/",
].forEach((token) => {
  assert(assetSource.includes(token), `员工资产 API 缺少关键契约: ${token}`);
});

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

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