import { createLogger } from "@open-mercato/shared/lib/logger";
const logger = createLogger("customers");
const customerInteractionFeatureIds = {
  unified: "customers.interactions.unified",
  legacyAdapters: "customers.interactions.legacy-adapters",
  externalSync: "customers.interactions.external-sync"
};
const customerInteractionFeatureAliases = {
  unified: ["customers_interactions_unified"],
  legacyAdapters: ["customers_interactions_legacy_adapters"],
  externalSync: ["customers_interactions_external_sync"]
};
const defaultCustomerInteractionFeatureFlags = {
  unified: false,
  legacyAdapters: true,
  externalSync: false
};
async function resolveBooleanFeature(service, tenantId, identifiers, fallback) {
  if (!service || !tenantId) return fallback;
  for (const identifier of identifiers) {
    try {
      const result = await service.getBoolConfig(identifier, tenantId);
      if (result.ok && typeof result.value === "boolean") {
        return result.value;
      }
    } catch {
      continue;
    }
  }
  return fallback;
}
function resolveFeatureToggleService(container) {
  try {
    return container.resolve("featureTogglesService");
  } catch (err) {
    logger.warn("Feature toggle service unavailable, using defaults", { component: "interactionFeatureFlags", err });
    return null;
  }
}
async function resolveCustomerInteractionFeatureFlags(container, tenantId) {
  const service = resolveFeatureToggleService(container);
  return {
    unified: await resolveBooleanFeature(
      service,
      tenantId,
      [customerInteractionFeatureIds.unified, ...customerInteractionFeatureAliases.unified],
      defaultCustomerInteractionFeatureFlags.unified
    ),
    legacyAdapters: await resolveBooleanFeature(
      service,
      tenantId,
      [customerInteractionFeatureIds.legacyAdapters, ...customerInteractionFeatureAliases.legacyAdapters],
      defaultCustomerInteractionFeatureFlags.legacyAdapters
    ),
    externalSync: await resolveBooleanFeature(
      service,
      tenantId,
      [customerInteractionFeatureIds.externalSync, ...customerInteractionFeatureAliases.externalSync],
      defaultCustomerInteractionFeatureFlags.externalSync
    )
  };
}
export {
  customerInteractionFeatureIds,
  resolveCustomerInteractionFeatureFlags
};
//# sourceMappingURL=interactionFeatureFlags.js.map
