import type { PubSub } from './pubsub/pubsub.types';

export const JOB_TYPE_NAME = 'job';

/** Pubsub channel for commands sent by a main process to workers or to other main processes. */
export const COMMAND_PUBSUB_CHANNEL = 'n8n.commands';

/** Pubsub channel for messages sent by workers in response to commands from main processes. */
export const WORKER_RESPONSE_PUBSUB_CHANNEL = 'n8n.worker-response';

/** Pubsub channel for MCP relay messages between main instances in multi-main queue mode. */
export const MCP_RELAY_PUBSUB_CHANNEL = 'n8n.mcp-relay';

/**
 * Max allowed size in bytes of a message relayed over the pubsub channel. Events
 * exceeding this are skipped (or trimmed) rather than bloating the channel.
 */
export const MAX_PUBSUB_PAYLOAD_BYTES = 5 * 1024 * 1024; // 5 MiB

/**
 * Commands that should be sent to the sender as well, e.g. during workflow activation and
 * deactivation in multi-main setup. */
export const SELF_SEND_COMMANDS = new Set<PubSub.Command['command']>([
	'add-webhooks-triggers-and-pollers',
	'remove-triggers-and-pollers',
	// The leader may itself enqueue an outbox record, so it must receive its own wake-up.
	'workflow-publish-wake-up',
]);

/**
 * Commands that should not be debounced when received, e.g. during webhook handling in
 * multi-main setup.
 */
export const IMMEDIATE_COMMANDS = new Set<PubSub.Command['command']>([
	'add-webhooks-triggers-and-pollers',
	'remove-triggers-and-pollers',
	'relay-execution-lifecycle-event',
	'relay-chat-stream-event',
	'relay-agent-execution-update',
	'resume-agent-workflow-tool',
	'cancel-agent-background-job',
	'relay-instance-ai-event',
	'relay-instance-ai-task-control',
	'agent-chat-subscription-changed',
	'agent-chat-integration-changed',
	// Correlated request/response pairs: the subscriber debounces by command name,
	// so debouncing would collapse concurrent requests (or their acks) into one.
	'agent-chat-leader-channel-request',
	'agent-chat-leader-channel-result',
	'cancel-test-run',
	'stop-execution',
	'display-workflow-activation',
	'display-workflow-deactivation',
	'display-workflow-activation-error',
	'display-workflow-publication-status',
	'workflow-publish-wake-up',
]);
