import { c as normalizeOptionalString } from "./string-coerce-Bje8XVt9.js";
import { i as getRuntimeConfig } from "./io-CYCDSQdU.js";
import "./config-ClYraoTC.js";
import { t as loadChannelOutboundAdapter } from "./load-CEeJTlg8.js";
//#region src/cli/send-runtime/channel-outbound-send.ts
function resolveRuntimeThreadId(opts) {
	return opts.messageThreadId ?? opts.threadId ?? opts.threadTs ?? void 0;
}
function resolveRuntimeReplyToId(opts) {
	const raw = opts.replyToMessageId ?? opts.replyToId;
	return raw == null ? void 0 : normalizeOptionalString(String(raw));
}
function createChannelOutboundRuntimeSend(params) {
	return { sendMessage: async (to, text, opts = {}) => {
		const outbound = await loadChannelOutboundAdapter(params.channelId);
		const threadId = resolveRuntimeThreadId(opts);
		const replyToId = resolveRuntimeReplyToId(opts);
		const buildContext = () => ({
			cfg: opts.cfg ?? getRuntimeConfig(),
			to,
			text,
			mediaUrl: opts.mediaUrl,
			mediaAccess: opts.mediaAccess,
			mediaLocalRoots: opts.mediaLocalRoots,
			mediaReadFile: opts.mediaReadFile,
			accountId: opts.accountId,
			threadId,
			replyToId,
			silent: opts.silent,
			forceDocument: opts.forceDocument,
			gifPlayback: opts.gifPlayback,
			gatewayClientScopes: opts.gatewayClientScopes
		});
		if (Boolean(opts.mediaUrl) && outbound?.sendMedia) return await outbound.sendMedia(buildContext());
		if (!outbound?.sendText) throw new Error(params.unavailableMessage);
		return await outbound.sendText(buildContext());
	} };
}
//#endregion
export { createChannelOutboundRuntimeSend };
