import { Time } from '@n8n/constants';

import { Config, Env } from '../decorators';

@Config
export class AiConfig {
	/** Whether AI features (such as AI nodes and AI assistant) are enabled globally. */
	@Env('N8N_AI_ENABLED')
	enabled: boolean = false;

	/**
	 * Maximum time in milliseconds to wait for an HTTP response from an AI service.
	 * Matches the maximum workflow execution timeout, EXECUTIONS_TIMEOUT_MAX (1 hour) so AI calls do not outlive executions.
	 * Default: 1 hour.
	 */
	@Env('N8N_AI_TIMEOUT_MAX')
	timeout: number = 1 * Time.hours.toMilliseconds;

	/**
	 * Whether workflow and node parameter values may be sent to AI providers.
	 * When false, only structure or placeholders are sent.
	 */
	@Env('N8N_AI_ALLOW_SENDING_PARAMETER_VALUES')
	allowSendingParameterValues: boolean = true;

	/**
	 * Maximum size in bytes of a single binary file (e.g. an image or PDF) that the
	 * AI Agent node will pass through to a model. Files above this are rejected
	 * before the request is sent. Default: 50 MB.
	 */
	@Env('N8N_AI_AGENT_MAX_PASSTHROUGH_BINARY_SIZE_BYTES')
	maxAgentPassthroughBinarySizeBytes: number = 50 * 1024 * 1024;

	get openAiDefaultHeaders(): Record<string, string> {
		// eslint-disable-next-line @typescript-eslint/naming-convention
		return { 'openai-platform': 'org-qkmJQuJ2WnvoIKMr2UJwIJkZ' };
	}
}
