import { d as normalizeChannelRouteRef } from "./channel-route-D7X5briz.js";
import { t as deliveryContextFromChannelRoute } from "./delivery-context.shared-BD1pk9kS.js";
import { n as resolveConversationDeliveryTarget } from "./delivery-context-aJ3bV9oU.js";
//#region src/channels/route-projection.ts
/** Converts a channel route back to legacy delivery context metadata. */
function deliveryContextFromRoute(route) {
	return deliveryContextFromChannelRoute(route);
}
/** Converts a persisted conversation reference into a channel route. */
function routeFromConversationRef(conversation) {
	if (!conversation) return;
	const target = resolveConversationDeliveryTarget({
		channel: conversation.channel,
		conversationId: conversation.conversationId,
		parentConversationId: conversation.parentConversationId
	});
	return normalizeChannelRouteRef({
		channel: conversation.channel,
		accountId: conversation.accountId,
		to: target.to,
		threadId: target.threadId,
		threadSource: target.threadId ? "target" : void 0
	});
}
/** Extracts a channel route from a session binding record. */
function routeFromBindingRecord(binding) {
	return routeFromConversationRef(binding?.conversation);
}
/** Projects route fields used by older session and delivery callers. */
function routeToDeliveryFields(route) {
	const deliveryContext = deliveryContextFromRoute(route);
	return {
		...deliveryContext ? { deliveryContext } : {},
		...deliveryContext?.channel ? { channel: deliveryContext.channel } : {},
		...deliveryContext?.to ? { to: deliveryContext.to } : {},
		...deliveryContext?.accountId ? { accountId: deliveryContext.accountId } : {},
		...deliveryContext?.threadId != null ? { threadId: deliveryContext.threadId } : {}
	};
}
//#endregion
export { routeFromConversationRef as n, routeToDeliveryFields as r, routeFromBindingRecord as t };
