import { r as logVerbose } from "./globals-TELeaDuk.js";
import { t as isCommandFlagEnabled } from "./commands.flags-CZN5Wwe1.js";
import { t as redactIdentifier } from "./redact-identifier-BRudYwZN.js";
import { a as isNativeCommandTurn, c as resolveCommandTurnContext } from "./command-turn-context-CmPEYNmV.js";
//#region src/auto-reply/reply/command-gates.ts
/** Builds the standard terminal text response shared by chat command handlers. */
function commandReply(text) {
	return {
		shouldContinue: false,
		reply: { text }
	};
}
/** Returns command arguments only when the complete slash-command token matches. */
function matchCommandPrefix(body, command) {
	return body === command ? "" : body.startsWith(`${command} `) ? body.slice(command.length).trim() : null;
}
/** Keeps matching, text-command enablement, and sender authorization in one owner. */
function defineAuthorizedTextCommand(options, run) {
	return async (params, allowTextCommands) => {
		if (!allowTextCommands) return null;
		const match = options.match(params.command.commandBodyNormalized, params);
		if (match === null) return null;
		const unauthorized = rejectUnauthorizedCommand(params, options.label);
		if (unauthorized) return options.silentUnauthorized ? { shouldContinue: false } : unauthorized;
		return (typeof options.ownerOnly === "function" ? options.ownerOnly(params, match) : options.ownerOnly) ? rejectNonOwnerCommand(params, options.label) ?? run(params, match) : run(params, match);
	};
}
function buildNativeCommandGateReply(text) {
	return commandReply(text);
}
function rejectUnauthorizedCommand(params, commandLabel) {
	if (params.command.isAuthorizedSender) return null;
	logVerbose(`Ignoring ${commandLabel} from unauthorized sender: ${redactIdentifier(params.command.senderId)}`);
	if (isNativeCommandTurn(resolveCommandTurnContext(params.ctx))) return buildNativeCommandGateReply("You are not authorized to use this command.");
	return { shouldContinue: false };
}
function rejectNonOwnerCommand(params, commandLabel) {
	if (params.command.senderIsOwner) return null;
	logVerbose(`Ignoring ${commandLabel} from non-owner sender: ${redactIdentifier(params.command.senderId)}`);
	if (isNativeCommandTurn(resolveCommandTurnContext(params.ctx))) return buildNativeCommandGateReply("You are not authorized to use this command.");
	return { shouldContinue: false };
}
function requireGatewayClientScope(params, config) {
	const scopes = params.ctx.GatewayClientScopes;
	if (!Array.isArray(scopes)) return null;
	if (config.allowedScopes.some((scope) => scopes.includes(scope))) return null;
	logVerbose(`Ignoring ${config.label} from gateway client missing scope: ${config.allowedScopes.join(" or ")}`);
	return commandReply(config.missingText);
}
function buildDisabledCommandReply(params) {
	const disabledVerb = params.disabledVerb ?? "is";
	const docsSuffix = params.docsUrl ? ` Docs: ${params.docsUrl}` : "";
	return { text: `⚠️ ${params.label} ${disabledVerb} disabled. Set commands.${params.configKey}=true to enable.${docsSuffix}` };
}
function requireCommandFlagEnabled(cfg, params) {
	if (isCommandFlagEnabled(cfg, params.configKey)) return null;
	return {
		shouldContinue: false,
		reply: buildDisabledCommandReply(params)
	};
}
//#endregion
export { rejectNonOwnerCommand as a, requireGatewayClientScope as c, matchCommandPrefix as i, commandReply as n, rejectUnauthorizedCommand as o, defineAuthorizedTextCommand as r, requireCommandFlagEnabled as s, buildDisabledCommandReply as t };
