import * as semver from "semver";
function compareVersions(a, b) {
  const cleanA = semver.valid(semver.coerce(a));
  const cleanB = semver.valid(semver.coerce(b));
  if (!cleanA) {
    throw new Error(`Invalid version string: "${a}". Expected a valid semver format (e.g., "1.2.3").`);
  }
  if (!cleanB) {
    throw new Error(`Invalid version string: "${b}". Expected a valid semver format (e.g., "1.2.3").`);
  }
  return semver.compare(cleanA, cleanB);
}
const upgradeActions = [
  {
    id: "customers.seed-interaction-statuses",
    version: "0.6.5",
    messageKey: "customers.config.upgradeActions.interactionStatuses.message",
    ctaKey: "customers.config.upgradeActions.interactionStatuses.cta",
    successKey: "customers.config.upgradeActions.interactionStatuses.success",
    loadingKey: "customers.config.upgradeActions.interactionStatuses.loading",
    // Existing tenants predate the `interaction_status` dictionary, so their status
    // dropdown is empty until seeded. New tenants get it via customers `seedDefaults`.
    // Lazy-imported so configs stays decoupled from customers (the catalog of actions
    // lives here, but customers code only loads when the action actually runs).
    run: async ({ em, tenantId, organizationId }) => {
      const [{ INTERACTION_STATUS_DEFAULTS }, { ensureDictionaryEntry }] = await Promise.all([
        import("@open-mercato/core/modules/customers/cli"),
        import("@open-mercato/core/modules/customers/commands/shared")
      ]);
      for (const entry of INTERACTION_STATUS_DEFAULTS) {
        await ensureDictionaryEntry(em, {
          tenantId,
          organizationId,
          kind: "interaction_status",
          value: entry.value,
          label: entry.label,
          color: entry.color,
          icon: entry.icon
        });
      }
    }
  }
];
function actionsUpToVersion(version) {
  return upgradeActions.filter((action) => compareVersions(action.version, version) <= 0).sort((a, b) => compareVersions(a.version, b.version) || a.id.localeCompare(b.id));
}
function findUpgradeAction(actionId, maxVersion) {
  const matches = actionsUpToVersion(maxVersion).filter((action) => action.id === actionId);
  if (!matches.length) return void 0;
  return matches[matches.length - 1];
}
export {
  actionsUpToVersion,
  compareVersions,
  findUpgradeAction,
  upgradeActions
};
//# sourceMappingURL=upgrade-actions.js.map
