import { TableNotFoundException } from "@mikro-orm/core";
import { CrudHttpError } from "@open-mercato/shared/lib/crud/errors";
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
const CUSTOMER_LABEL_TABLES = [
  "customer_labels",
  "customer_label_assignments"
];
function isMissingCustomerLabelTable(error) {
  if (error instanceof TableNotFoundException) {
    return true;
  }
  if (typeof error !== "object" || error === null) {
    return false;
  }
  const candidate = error;
  if (candidate.code === "42P01") {
    return true;
  }
  const message = candidate.message;
  if (typeof message !== "string") {
    return false;
  }
  return CUSTOMER_LABEL_TABLES.some((tableName) => message.includes(tableName));
}
async function createMissingCustomerLabelTablesError() {
  const { translate } = await resolveTranslations();
  return new CrudHttpError(503, {
    error: translate(
      "customers.errors.customer_label_tables_missing",
      "Customer label tables are missing. Run yarn db:migrate."
    )
  });
}
export {
  createMissingCustomerLabelTablesError,
  isMissingCustomerLabelTable
};
//# sourceMappingURL=table-errors.js.map
