/**
 * n8n-as-code Type Stubs
 *
 * Auto-generated by the n8n-as-code VS Code extension / CLI.
 * DO NOT EDIT - this file is regenerated automatically.
 *
 * Provides TypeScript types for .workflow.ts files without requiring
 * a local installation of @n8n-as-code/transformer.
 *
 * Exposes @n8n-as-code/transformer as an ambient module declaration.
 */

// =========================================================================
// GLOBAL AUGMENTATION
// Adds .out(), .in(), .uses(), .output to every object so that node
// properties (typed from their literal values) get full IntelliSense
// inside defineRouting() without explicit type casts.
// =========================================================================
interface Object {
    /** Regular output connector (index = output slot, default 0) */
    out(index?: number): {
        readonly _from: { node: string; output: number; isError?: boolean };
        to(input: { readonly _to: { node: string; input: number } }): void;
    };
    /** Regular input connector (index = input slot, default 0) */
    in(index?: number): { readonly _to: { node: string; input: number } };
    /** Error output connector */
    error(): {
        readonly _from: { node: string; output: number; isError?: boolean };
        to(input: { readonly _to: { node: string; input: number } }): void;
    };
    /** Declare AI/LangChain sub-node dependencies */
    uses(dependencies: {
        ai_languageModel?: any;
        ai_memory?: any;
        ai_outputParser?: any;
        ai_tool?: any[];
        ai_agent?: any;
        ai_chain?: any;
        ai_document?: any[];
        ai_textSplitter?: any;
        ai_embedding?: any;
        ai_retriever?: any;
        ai_reranker?: any;
        ai_vectorStore?: any;
    }): void;
    /** Output reference used as target of .uses() values */
    readonly output: any;
}

declare module '@n8n-as-code/transformer' {
    // =========================================================================
    // WORKFLOW SETTINGS
    // =========================================================================

    export interface WorkflowSettings {
        executionOrder?: 'v0' | 'v1' | 'v2';
        timeSavedMode?: 'fixed' | 'calculated';
        errorWorkflow?: string;
        timezone?: string;
        saveManualExecutions?: boolean;
        saveDataErrorExecution?: 'all' | 'none';
        saveExecutionProgress?: boolean;
        callerPolicy?: 'workflowsFromSameOwner' | 'any' | 'none';
        availableInMCP?: boolean;
        [key: string]: any;
    }

    // =========================================================================
    // DECORATOR METADATA
    // =========================================================================

    export interface WorkflowDecoratorOptions {
        /** Workflow ID (assigned by n8n) */
        id: string;
        /** Human-readable name */
        name: string;
        /** Whether the workflow is active */
        active: boolean;
        /** Workflow description */
        description?: string;
        /** Workflow execution settings */
        settings?: WorkflowSettings;
        /** Project ID for organization */
        projectId?: string;
        /** Project name */
        projectName?: string;
        /** Whether the workflow is archived */
        isArchived?: boolean;
    }

    export interface NodeDecoratorOptions {
        /** Unique identifier of the node (matches workflow JSON) */
        id?: string;
        /** Stable webhook ID assigned by n8n to webhook nodes */
        webhookId?: string;
        /** Display name shown in n8n UI */
        name: string;
        /** Node type identifier (e.g. "n8n-nodes-base.httpRequest") */
        type: string;
        /** Node version */
        version: number;
        /** Position [x, y] on the canvas */
        position?: [number, number];
        /** Credential references */
        credentials?: Record<string, { id: string; name: string }>;
        /** Error handling mode */
        onError?: 'continueErrorOutput' | 'continueRegularOutput' | 'stopWorkflow';
        /** Always output data even when the node has no results */
        alwaysOutputData?: boolean;
        /** Execute this node only once, for the first item */
        executeOnce?: boolean;
        /** Retry on failure */
        retryOnFail?: boolean;
        /** Maximum number of retry attempts (used with retryOnFail) */
        maxTries?: number;
        /** Milliseconds to wait between retries (used with retryOnFail) */
        waitBetweenTries?: number;
    }

    // =========================================================================
    // AI / LANGCHAIN DEPENDENCY MAP (.uses())
    // =========================================================================

    /** Proxy object with an `.output` accessor (returned by AI/LangChain nodes) */
    export interface NodeOutput {
        readonly output: NodeOutput;
    }

    export interface AIDependencyMap {
        /** Language model (e.g. OpenAI, Anthropic) */
        ai_languageModel?: NodeOutput;
        /** Conversation memory */
        ai_memory?: NodeOutput;
        /** Structured output parser */
        ai_outputParser?: NodeOutput;
        /** Tool nodes (can be multiple) */
        ai_tool?: NodeOutput[];
        /** Sub-agent */
        ai_agent?: NodeOutput;
        /** LangChain chain */
        ai_chain?: NodeOutput;
        /** Document loaders (can be multiple) */
        ai_document?: NodeOutput[];
        /** Text splitter */
        ai_textSplitter?: NodeOutput;
        /** Embedding model */
        ai_embedding?: NodeOutput;
        /** Vector store retriever */
        ai_retriever?: NodeOutput;
        /** Result reranker */
        ai_reranker?: NodeOutput;
        /** Vector store */
        ai_vectorStore?: NodeOutput;
    }

    // =========================================================================
    // FLUENT CONNECTION API (.out().to(), .uses())
    // =========================================================================

    export interface InputConnection {
        readonly _to: { node: string; input: number };
    }

    export interface OutputConnection {
        readonly _from: { node: string; output: number; isError?: boolean };
        /** Connect this output to a node input */
        to(input: InputConnection): void;
    }

    /** Proxy wrapping each class property in defineRouting() */
    export interface NodeProxy extends NodeOutput {
        /** Regular output connector (index = output index, default 0) */
        out(index?: number): OutputConnection;
        /** Regular input connector (index = input index, default 0) */
        in(index?: number): InputConnection;
        /** Error output connector */
        error(): OutputConnection;
        /** Declare AI/LangChain sub-node dependencies */
        uses(dependencies: AIDependencyMap): void;
    }

    // =========================================================================
    // DECORATORS
    // =========================================================================

    /**
     * Marks a class as an n8n workflow.
     * 
     * @example
     * ```ts
     * @workflow({ id: 'abc123', name: 'My Workflow', active: false })
     * export class MyWorkflow { ... }
     * ```
     */
    export function workflow(options: WorkflowDecoratorOptions): ClassDecorator;

    /**
     * Marks a class property as an n8n node.
     * The property value is used as node parameters.
     * 
     * @example
     * ```ts
     * @node({ name: 'HTTP Request', type: 'n8n-nodes-base.httpRequest', version: 4.2, position: [300, 200] })
     * MyHttp = { url: 'https://api.example.com' };
     * ```
     */
    export function node(options: NodeDecoratorOptions): PropertyDecorator;

    /**
     * Marks a method as the routing/connections definition.
     * Inside this method, use `.out().to()` for regular connections
     * and `.uses()` for AI/LangChain sub-node connections.
     * 
     * @example
     * ```ts
     * @links()
     * defineRouting() {
     *     this.Trigger.out(0).to(this.Agent.in(0));
     *     this.Agent.uses({ ai_languageModel: this.Model.output });
     * }
     * ```
     */
    export function links(): MethodDecorator;
}
