import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
const SUPPORTED_COMPANY_PROFILE_KEYS = /* @__PURE__ */ new Set([
  "legalName",
  "brandName",
  "domain",
  "websiteUrl",
  "industry",
  "sizeBucket",
  "annualRevenue"
]);
const IGNORED_ROUND_TRIP_KEYS = /* @__PURE__ */ new Set(["id", "updatedAt"]);
function normalizeCompanyProfilePayload(payload, translate) {
  if (!("profile" in payload) || payload.profile === void 0) {
    return payload;
  }
  const profile = payload.profile;
  if (profile === null || typeof profile !== "object" || Array.isArray(profile)) {
    throw new CrudHttpError(400, {
      error: translate(
        "customers.errors.profile_must_be_object",
        "profile must be an object"
      )
    });
  }
  const profileRecord = profile;
  const result = { ...payload };
  delete result.profile;
  for (const key of Object.keys(profileRecord)) {
    if (IGNORED_ROUND_TRIP_KEYS.has(key)) {
      continue;
    }
    if (!SUPPORTED_COMPANY_PROFILE_KEYS.has(key)) {
      throw new CrudHttpError(400, {
        error: translate(
          "customers.errors.profile_unsupported_field",
          "Unsupported profile field: {{field}}",
          { field: key }
        )
      });
    }
    if (!(key in result) || result[key] === void 0) {
      result[key] = profileRecord[key];
    }
  }
  return result;
}
export {
  normalizeCompanyProfilePayload
};
//# sourceMappingURL=payload.js.map
