import { createLogger } from "../../../../src/utils/logger/index.js";
import { init_logger } from "../../../../src/utils/logger.js";
import { resolveStandardPairingPath } from "../../../../src/channels/pairing/paths.js";
import { issuePairingChallenge } from "../../../../src/channels/pairing/pairing-challenge.js";
import { createFeishuClient } from "../transport/client/client.js";
//#region extensions/feishu/src/pairing/feishu-pairing-prompt.ts
init_logger();
const log = createLogger("FeishuPairing");
/**
* When DM policy is `pairing` and the user is not yet allowlisted, send a one-time pairing code + CLI hint.
*/
async function sendFeishuPairingPromptIfNeeded(params) {
	if (params.isGroup) return;
	const { account, messageId, threadId, senderId, senderName } = params;
	if (!messageId.trim() || !senderId.trim()) return;
	try {
		const { api } = createFeishuClient(account);
		await issuePairingChallenge({
			channel: "feishu",
			pairingFilePath: resolveStandardPairingPath("feishu", account.accountId),
			accountId: account.accountId,
			senderId,
			senderIdLine: `Your Feishu sender id: ${senderId}`,
			meta: senderName ? { displayName: senderName } : void 0,
			sendPairingReply: async (text) => {
				await api.im.message.reply({
					path: { message_id: messageId },
					data: {
						msg_type: "text",
						content: JSON.stringify({ text }),
						...threadId ? { reply_in_thread: true } : {}
					}
				});
			},
			onCreated: ({ code }) => {
				log.info({
					accountId: account.accountId,
					senderId,
					code
				}, "Feishu pairing code issued");
			},
			onReplyError: (err) => {
				log.warn({
					err,
					accountId: account.accountId,
					senderId
				}, "Feishu pairing reply failed");
			}
		});
	} catch (err) {
		log.warn({
			err,
			accountId: account.accountId,
			senderId
		}, "Feishu pairing prompt failed");
	}
}
//#endregion
export { sendFeishuPairingPromptIfNeeded };

//# sourceMappingURL=feishu-pairing-prompt.js.map