const require_chunk = require('./chunk-DWy1uDak.cjs');
const require_utils = require('./utils-C5DuiZoe.cjs');
const __sentry_node = require_chunk.__toESM(require("@sentry/node"));

//#region src/tools/search-events/formatters.ts
/**
* Format an explanation for how a natural language query was translated
*/
function formatExplanation(explanation) {
	return `## How I interpreted your query\n\n${explanation}`;
}
/**
* Format error event results for display
*/
function formatErrorResults(params) {
	const { eventData, naturalLanguageQuery, includeExplanation, apiService, organizationSlug, explorerUrl, sentryQuery, fields, explanation } = params;
	let output = `# Search Results for "${naturalLanguageQuery}"\n\n`;
	if (require_utils.isAggregateQuery(fields)) output += `⚠️ **IMPORTANT**: Display these aggregate results as a data table with proper column alignment and formatting.\n\n`;
	else output += `⚠️ **IMPORTANT**: Display these errors as highlighted alert cards with color-coded severity levels and clickable Event IDs.\n\n`;
	if (includeExplanation && explanation) {
		output += formatExplanation(explanation);
		output += `\n\n`;
	}
	output += `**View these results in Sentry**:\n${explorerUrl}\n`;
	output += `_Please share this link with the user to view the search results in their Sentry dashboard._\n\n`;
	if (eventData.length === 0) {
		__sentry_node.logger.info(__sentry_node.logger.fmt`No error events found for query: ${naturalLanguageQuery}`, {
			query: sentryQuery,
			fields,
			organizationSlug,
			dataset: "errors"
		});
		output += `No results found.\n\n`;
		output += `Try being more specific or using different terms in your search.\n`;
		return output;
	}
	output += `Found ${eventData.length} ${require_utils.isAggregateQuery(fields) ? "aggregate result" : "error"}${eventData.length === 1 ? "" : "s"}:\n\n`;
	if (require_utils.isAggregateQuery(fields)) {
		output += "```json\n";
		output += JSON.stringify(eventData, null, 2);
		output += "\n```\n\n";
	} else {
		const priorityFields = [
			"title",
			"issue",
			"project",
			"level",
			"error.type",
			"message",
			"culprit",
			"timestamp",
			"last_seen()",
			"count()"
		];
		for (const event of eventData) {
			const title = require_utils.getStringValue(event, "title") || require_utils.getStringValue(event, "message") || require_utils.getStringValue(event, "error.value") || "Error Event";
			output += `## ${title}\n\n`;
			for (const field of priorityFields) if (field in event && event[field] !== null && event[field] !== void 0) {
				const value = event[field];
				if (field === "issue" && typeof value === "string") {
					output += `**Issue ID**: ${value}\n`;
					output += `**Issue URL**: ${apiService.getIssueUrl(organizationSlug, value)}\n`;
				} else output += `**${field}**: ${value}\n`;
			}
			const displayedFields = new Set([...priorityFields, "id"]);
			for (const [key, value] of Object.entries(event)) if (!displayedFields.has(key) && value !== null && value !== void 0) output += `**${key}**: ${value}\n`;
			output += "\n";
		}
	}
	output += "## Next Steps\n\n";
	output += "- Get more details about a specific error: Use the Issue ID\n";
	output += "- View error groups: Navigate to the Issues page in Sentry\n";
	output += "- Set up alerts: Configure alert rules for these error patterns\n";
	return output;
}
/**
* Format log event results for display
*/
function formatLogResults(params) {
	const { eventData, naturalLanguageQuery, includeExplanation, apiService, organizationSlug, explorerUrl, sentryQuery, fields, explanation } = params;
	let output = `# Search Results for "${naturalLanguageQuery}"\n\n`;
	if (require_utils.isAggregateQuery(fields)) output += `⚠️ **IMPORTANT**: Display these aggregate results as a data table with proper column alignment and formatting.\n\n`;
	else output += `⚠️ **IMPORTANT**: Display these logs in console format with monospace font, color-coded severity (🔴 ERROR, 🟡 WARN, 🔵 INFO), and preserve timestamps.\n\n`;
	if (includeExplanation && explanation) {
		output += formatExplanation(explanation);
		output += `\n\n`;
	}
	output += `**View these results in Sentry**:\n${explorerUrl}\n`;
	output += `_Please share this link with the user to view the search results in their Sentry dashboard._\n\n`;
	if (eventData.length === 0) {
		__sentry_node.logger.info(__sentry_node.logger.fmt`No log events found for query: ${naturalLanguageQuery}`, {
			query: sentryQuery,
			fields,
			organizationSlug,
			dataset: "logs"
		});
		output += `No results found.\n\n`;
		output += `Try being more specific or using different terms in your search.\n`;
		return output;
	}
	output += `Found ${eventData.length} ${require_utils.isAggregateQuery(fields) ? "aggregate result" : "log"}${eventData.length === 1 ? "" : "s"}:\n\n`;
	if (require_utils.isAggregateQuery(fields)) {
		output += "```json\n";
		output += JSON.stringify(eventData, null, 2);
		output += "\n```\n\n";
	} else {
		output += "```console\n";
		for (const event of eventData) {
			const timestamp = require_utils.getStringValue(event, "timestamp", "N/A");
			const severity = require_utils.getStringValue(event, "severity", "info");
			const message = require_utils.getStringValue(event, "message", "No message");
			const severityUpper = severity.toUpperCase();
			const severityEmojis = {
				ERROR: "🔴",
				FATAL: "🔴",
				WARN: "🟡",
				WARNING: "🟡",
				INFO: "🔵",
				DEBUG: "⚫",
				TRACE: "⚫"
			};
			const severityEmoji = severityEmojis[severityUpper] || "🔵";
			output += `${timestamp} ${severityEmoji} [${severityUpper.padEnd(5)}] ${message}\n`;
		}
		output += "```\n\n";
		output += "## Log Details\n\n";
		const priorityFields = [
			"message",
			"severity",
			"severity_number",
			"timestamp",
			"project",
			"trace",
			"sentry.item_id"
		];
		for (let i = 0; i < eventData.length; i++) {
			const event = eventData[i];
			output += `### Log ${i + 1}\n`;
			for (const field of priorityFields) if (field in event && event[field] !== null && event[field] !== void 0) {
				const value = event[field];
				if (field === "trace" && typeof value === "string") {
					output += `- **Trace ID**: ${value}\n`;
					output += `- **Trace URL**: ${apiService.getTraceUrl(organizationSlug, value)}\n`;
				} else output += `- **${field}**: ${value}\n`;
			}
			const displayedFields = new Set([...priorityFields, "id"]);
			for (const [key, value] of Object.entries(event)) if (!displayedFields.has(key) && value !== null && value !== void 0) output += `- **${key}**: ${value}\n`;
			output += "\n";
		}
	}
	output += "## Next Steps\n\n";
	output += "- View related traces: Click on the Trace URL if available\n";
	output += "- Filter by severity: Adjust your query to focus on specific log levels\n";
	output += "- Export logs: Use the Sentry web interface for bulk export\n";
	return output;
}
/**
* Format span/trace event results for display
*/
function formatSpanResults(params) {
	const { eventData, naturalLanguageQuery, includeExplanation, apiService, organizationSlug, explorerUrl, sentryQuery, fields, explanation } = params;
	let output = `# Search Results for "${naturalLanguageQuery}"\n\n`;
	if (require_utils.isAggregateQuery(fields)) output += `⚠️ **IMPORTANT**: Display these aggregate results as a data table with proper column alignment and formatting.\n\n`;
	else output += `⚠️ **IMPORTANT**: Display these traces as a performance timeline with duration bars and hierarchical span relationships.\n\n`;
	if (includeExplanation && explanation) {
		output += formatExplanation(explanation);
		output += `\n\n`;
	}
	output += `**View these results in Sentry**:\n${explorerUrl}\n`;
	output += `_Please share this link with the user to view the search results in their Sentry dashboard._\n\n`;
	if (eventData.length === 0) {
		__sentry_node.logger.info(__sentry_node.logger.fmt`No span events found for query: ${naturalLanguageQuery}`, {
			query: sentryQuery,
			fields,
			organizationSlug,
			dataset: "spans"
		});
		output += `No results found.\n\n`;
		output += `Try being more specific or using different terms in your search.\n`;
		return output;
	}
	output += `Found ${eventData.length} ${require_utils.isAggregateQuery(fields) ? `aggregate result${eventData.length === 1 ? "" : "s"}` : `trace${eventData.length === 1 ? "" : "s"}/span${eventData.length === 1 ? "" : "s"}`}:\n\n`;
	if (require_utils.isAggregateQuery(fields)) {
		output += "```json\n";
		output += JSON.stringify(eventData, null, 2);
		output += "\n```\n\n";
	} else {
		const priorityFields = [
			"id",
			"span.op",
			"span.description",
			"transaction",
			"span.duration",
			"span.status",
			"trace",
			"project",
			"timestamp"
		];
		for (const event of eventData) {
			const title = require_utils.getStringValue(event, "span.description") || require_utils.getStringValue(event, "transaction") || require_utils.getStringValue(event, "span.op") || "Span";
			output += `## ${title}\n\n`;
			for (const field of priorityFields) if (field in event && event[field] !== null && event[field] !== void 0) {
				const value = event[field];
				if (field === "trace" && typeof value === "string") {
					output += `**Trace ID**: ${value}\n`;
					output += `**Trace URL**: ${apiService.getTraceUrl(organizationSlug, value)}\n`;
				} else if (field === "span.duration" && typeof value === "number") output += `**${field}**: ${value}ms\n`;
				else output += `**${field}**: ${value}\n`;
			}
			const displayedFields = new Set([...priorityFields, "id"]);
			for (const [key, value] of Object.entries(event)) if (!displayedFields.has(key) && value !== null && value !== void 0) output += `**${key}**: ${value}\n`;
			output += "\n";
		}
	}
	output += "## Next Steps\n\n";
	output += "- View the full trace: Click on the Trace URL above\n";
	output += "- Search for related spans: Modify your query to be more specific\n";
	output += "- Export data: Use the Sentry web interface for advanced analysis\n";
	return output;
}

//#endregion
Object.defineProperty(exports, 'formatErrorResults', {
  enumerable: true,
  get: function () {
    return formatErrorResults;
  }
});
Object.defineProperty(exports, 'formatExplanation', {
  enumerable: true,
  get: function () {
    return formatExplanation;
  }
});
Object.defineProperty(exports, 'formatLogResults', {
  enumerable: true,
  get: function () {
    return formatLogResults;
  }
});
Object.defineProperty(exports, 'formatSpanResults', {
  enumerable: true,
  get: function () {
    return formatSpanResults;
  }
});
//# sourceMappingURL=formatters-DMlTJcHW.cjs.map