"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgenticHub = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class AgenticHub {
    constructor() {
        this.description = {
            displayName: 'Agentic Hub',
            name: 'agenticHub',
            icon: 'file:agentic-hub.svg',
            group: ['transform'],
            version: 1,
            description: 'Complete Agentic Hub API integration - Manage projects, workflows, agents, content, conversations, messages, and files',
            defaults: {
                name: 'Agentic Hub',
            },
            subtitle: '={{$parameter["resource"]}} / {{$parameter["operation"]}}',
            inputs: ["main"],
            outputs: ["main"],
            usableAsTool: true,
            credentials: [
                {
                    name: 'agenticHubApi',
                    required: true,
                },
            ],
            properties: [
                {
                    displayName: 'Resource',
                    name: 'resource',
                    type: 'options',
                    noDataExpression: true,
                    options: [
                        {
                            name: 'Agent',
                            value: 'agent',
                            description: 'Manage AI agents',
                        },
                        {
                            name: 'Company',
                            value: 'company',
                            description: 'Manage company details, projects, and workflows',
                        },
                        {
                            name: 'Content',
                            value: 'content',
                            description: 'Manage content (text and FAQ)',
                        },
                        {
                            name: 'Conversation',
                            value: 'conversation',
                            description: 'Manage conversations',
                        },
                        {
                            name: 'File',
                            value: 'file',
                            description: 'Manage files',
                        },
                        {
                            name: 'Message',
                            value: 'message',
                            description: 'Manage messages',
                        },
                        {
                            name: 'Project',
                            value: 'project',
                            description: 'Manage projects',
                        },
                        {
                            name: 'Workflow',
                            value: 'workflow',
                            description: 'Manage workflows',
                        },
                    ],
                    default: 'project',
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['project'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new project',
                            action: 'Create a project',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a project',
                            action: 'Delete a project',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific project by ID',
                            action: 'Get a project',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many projects for the authenticated company',
                            action: 'Get many projects',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a project',
                            action: 'Update a project',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Project ID',
                    name: 'projectId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Project ID',
                    description: 'The unique identifier of the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'name',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter project name',
                    description: 'Project name. Must be unique within the company.',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Description',
                    name: 'description',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter project description',
                    description: 'Detailed description of the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'status',
                    type: 'options',
                    default: 'active',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Project status',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'updateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter project name',
                    description: 'New name for the project',
                    displayOptions: {
                        show: {
                            resource: ['project'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new workflow',
                            action: 'Create a workflow',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a workflow',
                            action: 'Delete a workflow',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific workflow by ID',
                            action: 'Get a workflow',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many workflows for the authenticated company',
                            action: 'Get many workflows',
                        },
                        {
                            name: 'Send Message',
                            value: 'sendMessage',
                            description: 'Create a conversation and send a message in one call',
                            action: 'Send a message in a workflow',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a workflow',
                            action: 'Update a workflow',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Workflow ID',
                    name: 'workflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'The unique identifier of the workflow',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['get', 'update', 'delete', 'sendMessage'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'workflowName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter workflow name',
                    description: 'Workflow name. Must be unique within the project.',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Project ID',
                    name: 'workflowProjectId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Project ID',
                    description: 'ID of the project to which the workflow belongs',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Description',
                    name: 'workflowDescription',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter workflow description',
                    description: 'Detailed description of the workflow and its purpose',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'workflowStatus',
                    type: 'options',
                    default: 'active',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Workflow status',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'workflowUpdateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter workflow name',
                    description: 'New name for the workflow',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'sendMessageSessionId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Session ID',
                    description: 'Unique session identifier for the conversation',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['sendMessage'],
                        },
                    },
                },
                {
                    displayName: 'Message Content',
                    name: 'sendMessageContent',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter message content',
                    description: 'The text content of the message',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['sendMessage'],
                        },
                    },
                },
                {
                    displayName: 'Direction',
                    name: 'sendMessageDirection',
                    type: 'options',
                    default: 0,
                    required: true,
                    options: [
                        {
                            name: 'From User to Agent (Incoming)',
                            value: 0,
                        },
                        {
                            name: 'From Agent to User (Outgoing)',
                            value: 1,
                        },
                        {
                            name: 'Human Agent',
                            value: 2,
                        },
                    ],
                    description: 'Message direction: 0 = incoming, 1 = outgoing, 2 = human agent',
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['sendMessage'],
                        },
                    },
                },
                {
                    displayName: 'Conversation Options',
                    name: 'sendMessageConversationOptions',
                    type: 'collection',
                    placeholder: 'Add Option',
                    default: {},
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['sendMessage'],
                        },
                    },
                    options: [
                        {
                            displayName: 'Conversation Status',
                            name: 'status',
                            type: 'number',
                            default: 1,
                            description: 'Conversation status number',
                        },
                        {
                            displayName: 'IP Address',
                            name: 'ipAddress',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter IP address',
                            description: "User's IP address for tracking",
                        },
                        {
                            displayName: 'Is Handled By Human',
                            name: 'isHandledByHuman',
                            type: 'boolean',
                            default: false,
                            description: 'Whether the conversation is being handled by a human',
                        },
                        {
                            displayName: 'Last Context',
                            name: 'lastContext',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter last context',
                            description: 'Last context/state of the conversation',
                        },
                        {
                            displayName: 'Order ID',
                            name: 'orderId',
                            type: 'number',
                            default: 0,
                            description: 'Order ID associated with the conversation',
                        },
                        {
                            displayName: 'Overall Sentiment',
                            name: 'overallSentiment',
                            type: 'number',
                            default: 100,
                            description: 'Overall sentiment score (0-100)',
                            typeOptions: {
                                minValue: 0,
                                maxValue: 100,
                            },
                        },
                        {
                            displayName: 'Phone Number',
                            name: 'phoneNumber',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter phone number',
                            description: "User's phone number",
                        },
                        {
                            displayName: 'Requires Human Attention',
                            name: 'requiresHumanAttention',
                            type: 'boolean',
                            default: false,
                            description: 'Whether the conversation requires human intervention',
                        },
                    ],
                },
                {
                    displayName: 'Message Options',
                    name: 'sendMessageOptions',
                    type: 'collection',
                    placeholder: 'Add Option',
                    default: {},
                    displayOptions: {
                        show: {
                            resource: ['workflow'],
                            operation: ['sendMessage'],
                        },
                    },
                    options: [
                        {
                            displayName: 'Error Message',
                            name: 'errorMessage',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter error message',
                            description: 'Error description if applicable',
                        },
                        {
                            displayName: 'Message SID',
                            name: 'messageSid',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter external message ID',
                            description: 'External message identifier (e.g., WhatsApp message ID)',
                        },
                        {
                            displayName: 'Message Status',
                            name: 'status',
                            type: 'number',
                            default: 0,
                            description: 'Message status code',
                        },
                        {
                            displayName: 'Sentiment Score',
                            name: 'sentimentScore',
                            type: 'number',
                            default: 100,
                            description: 'Sentiment score for this specific message (0-100)',
                            typeOptions: {
                                minValue: 0,
                                maxValue: 100,
                            },
                        },
                        {
                            displayName: 'Template ID',
                            name: 'templateId',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter Template ID',
                            description: 'Template ID if using a template for this message',
                        },
                    ],
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new agent',
                            action: 'Create an agent',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete an agent',
                            action: 'Delete an agent',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific agent by ID',
                            action: 'Get an agent',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many agents for the authenticated company',
                            action: 'Get many agents',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update an agent',
                            action: 'Update an agent',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Agent ID',
                    name: 'agentId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Agent ID',
                    description: 'The unique identifier of the agent',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'agentName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter agent name',
                    description: 'Agent name. Must be unique within the workflow.',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'agentWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the agent belongs',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Main Prompt',
                    name: 'mainPrompt',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter main prompt',
                    description: "Main prompt that defines the agent's behavior",
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Dynamic Fields',
                    name: 'dynamicFields',
                    type: 'json',
                    default: '[]',
                    placeholder: '[]',
                    description: 'Additional dynamic fields for configuring the agent (JSON array)',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Is Active',
                    name: 'isActive',
                    type: 'boolean',
                    default: true,
                    description: 'Whether the agent is active',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['create', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'agentUpdateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter agent name',
                    description: 'New name for the agent',
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Main Prompt',
                    name: 'updateMainPrompt',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    placeholder: 'Enter main prompt',
                    description: "Updated prompt that defines the agent's behavior",
                    displayOptions: {
                        show: {
                            resource: ['agent'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['content'],
                        },
                    },
                    options: [
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create new content',
                            action: 'Create content',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete content',
                            action: 'Delete content',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific content by ID',
                            action: 'Get content',
                        },
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many content for the authenticated company',
                            action: 'Get many content',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update content',
                            action: 'Update content',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Content ID',
                    name: 'contentId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Content ID',
                    description: 'The unique identifier of the content',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['get', 'update', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'contentWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the content belongs',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Title',
                    name: 'contentTitle',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter content title',
                    description: 'Content title',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Type',
                    name: 'contentType',
                    type: 'options',
                    default: 'text',
                    required: true,
                    options: [
                        {
                            name: 'Text',
                            value: 'text',
                        },
                        {
                            name: 'FAQ',
                            value: 'faq',
                        },
                    ],
                    description: 'Content type',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'contentText',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter content text',
                    description: 'The content itself (for text type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                            contentType: ['text'],
                        },
                    },
                },
                {
                    displayName: 'FAQ Items',
                    name: 'faqItems',
                    type: 'json',
                    default: '[]',
                    required: true,
                    placeholder: '[{"ID": "faq1", "question": "Question?", "answer": "Answer"}]',
                    description: 'Array of FAQ items. Each item must have ID (string), question (string), and answer (string).',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['create'],
                            contentType: ['faq'],
                        },
                    },
                },
                {
                    displayName: 'Title',
                    name: 'contentUpdateTitle',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter content title',
                    description: 'Updated title',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'contentUpdateText',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    placeholder: 'Enter content text',
                    description: 'Updated content (for text type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'FAQ Items',
                    name: 'updateFaqItems',
                    type: 'json',
                    default: '',
                    placeholder: '[{"ID": "faq1", "question": "Question?", "answer": "Answer"}]',
                    description: 'Updated array of questions and answers (for faq type)',
                    displayOptions: {
                        show: {
                            resource: ['content'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many conversations for the authenticated company',
                            action: 'Get many conversations',
                        },
                        {
                            name: 'Create or Update',
                            value: 'create',
                            description: 'Create or update a conversation',
                            action: 'Create or update a conversation',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific conversation by ID',
                            action: 'Get a conversation',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update a conversation',
                            action: 'Update a conversation',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Conversation ID',
                    name: 'conversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'The unique identifier of the conversation',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['get', 'update'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'sessionId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Session ID',
                    description: 'Unique session identifier. Identifies the specific conversation.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'conversationWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the conversation belongs',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'IP Address',
                    name: 'ipAddress',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter IP address',
                    description: "User's IP address. Used for tracking and security.",
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Phone Number',
                    name: 'phoneNumber',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter phone number',
                    description: "User's phone number (if relevant)",
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Status',
                    name: 'conversationStatus',
                    type: 'number',
                    default: 1,
                    description: 'Conversation status. Number representing the conversation state.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Requires Human Attention',
                    name: 'requiresHumanAttention',
                    type: 'boolean',
                    default: false,
                    description: 'Whether the conversation requires human attention',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Is Handled By Human',
                    name: 'isHandledByHuman',
                    type: 'boolean',
                    default: false,
                    description: 'Whether the conversation is handled by a human',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Last Context',
                    name: 'lastContext',
                    type: 'string',
                    typeOptions: {
                        rows: 2,
                    },
                    default: '',
                    placeholder: 'Enter last context',
                    description: 'Last context in the conversation. Additional information about the conversation state.',
                    displayOptions: {
                        show: {
                            resource: ['conversation'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['message'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many messages for a conversation',
                            action: 'Get many messages',
                        },
                        {
                            name: 'Create',
                            value: 'create',
                            description: 'Create a new message (with optional conversation auto-creation)',
                            action: 'Create a message',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific message by ID',
                            action: 'Get a message',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'Conversation ID',
                    name: 'messageConversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'ID of the conversation (query parameter for Get Many, required for legacy mode Create)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['getAll'],
                        },
                    },
                },
                {
                    displayName: 'Message ID',
                    name: 'messageId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Message ID',
                    description: 'The unique identifier of the message',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['get'],
                        },
                    },
                },
                {
                    displayName: 'Mode',
                    name: 'mode',
                    type: 'options',
                    default: 'unified',
                    options: [
                        {
                            name: 'Unified (Auto-Create Conversation)',
                            value: 'unified',
                            description: 'Automatically create or update conversation based on sessionId',
                        },
                        {
                            name: 'Legacy (Use conversationId)',
                            value: 'legacy',
                            description: 'Use existing conversationId (backward compatibility)',
                        },
                    ],
                    description: 'Message creation mode',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Session ID',
                    name: 'messageSessionId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Session ID',
                    description: 'Unique session identifier. Required if unified mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Workflow ID',
                    name: 'messageWorkflowId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Workflow ID',
                    description: 'ID of the workflow to which the conversation belongs. Required if unified mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                },
                {
                    displayName: 'Conversation ID',
                    name: 'legacyConversationId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Conversation ID',
                    description: 'ID of the conversation to which the message belongs. Required if legacy mode.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['legacy'],
                        },
                    },
                },
                {
                    displayName: 'Content',
                    name: 'messageContent',
                    type: 'string',
                    typeOptions: {
                        rows: 4,
                    },
                    default: '',
                    required: true,
                    placeholder: 'Enter message content',
                    description: 'Message content. The text of the message.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Direction',
                    name: 'direction',
                    type: 'options',
                    default: 0,
                    required: true,
                    options: [
                        {
                            name: 'From User to Agent',
                            value: 0,
                        },
                        {
                            name: 'From Agent to User',
                            value: 1,
                        },
                    ],
                    description: 'Message direction: 0 (from user to agent) or 1 (from agent to user)',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                },
                {
                    displayName: 'Conversation Options',
                    name: 'messageConversationOptions',
                    type: 'collection',
                    placeholder: 'Add Option',
                    default: {},
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['unified'],
                        },
                    },
                    options: [
                        {
                            displayName: 'Conversation Status',
                            name: 'status',
                            type: 'number',
                            default: 1,
                            description: 'Conversation status. Number representing the conversation state.',
                        },
                        {
                            displayName: 'Is Handled By Human',
                            name: 'isHandledByHuman',
                            type: 'boolean',
                            default: false,
                            description: 'Whether the conversation is handled by a human',
                        },
                        {
                            displayName: 'Overall Sentiment',
                            name: 'overallSentiment',
                            type: 'number',
                            default: 100,
                            description: 'Overall sentiment score for the conversation',
                            typeOptions: {
                                minValue: 0,
                                maxValue: 100,
                            },
                        },
                        {
                            displayName: 'Phone Number',
                            name: 'phoneNumber',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter phone number',
                            description: "User's phone number (if relevant)",
                        },
                        {
                            displayName: 'Requires Human Attention',
                            name: 'requiresHumanAttention',
                            type: 'boolean',
                            default: false,
                            description: 'Whether conversation requires human intervention',
                        },
                    ],
                },
                {
                    displayName: 'Session ID',
                    name: 'legacySessionId',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter Session ID',
                    description: 'Session identifier. Used when conversation object is not provided.',
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                            mode: ['legacy'],
                        },
                    },
                },
                {
                    displayName: 'Message Options',
                    name: 'messageOptions',
                    type: 'collection',
                    placeholder: 'Add Option',
                    default: {},
                    displayOptions: {
                        show: {
                            resource: ['message'],
                            operation: ['create'],
                        },
                    },
                    options: [
                        {
                            displayName: 'Error Message',
                            name: 'errorMessage',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter error message',
                            description: 'Error message if message creation failed',
                        },
                        {
                            displayName: 'Message SID',
                            name: 'messageSid',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter Message SID',
                            description: 'External message identifier (e.g., WhatsApp message ID)',
                        },
                        {
                            displayName: 'Sentiment Score',
                            name: 'sentimentScore',
                            type: 'number',
                            default: 100,
                            description: 'Sentiment score for this specific message',
                            typeOptions: {
                                minValue: 0,
                                maxValue: 100,
                            },
                        },
                        {
                            displayName: 'Status',
                            name: 'status',
                            type: 'number',
                            default: 0,
                            description: 'Message status',
                        },
                        {
                            displayName: 'Template ID',
                            name: 'templateId',
                            type: 'string',
                            default: '',
                            placeholder: 'Enter Template ID',
                            description: 'ID of the template used for this message (if applicable)',
                        },
                    ],
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['file'],
                        },
                    },
                    options: [
                        {
                            name: 'Get Many',
                            value: 'getAll',
                            description: 'Get many files for the authenticated company',
                            action: 'Get many files',
                        },
                        {
                            name: 'Get by ID',
                            value: 'get',
                            description: 'Get a specific file by ID',
                            action: 'Get a file',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete a file',
                            action: 'Delete a file',
                        },
                    ],
                    default: 'getAll',
                },
                {
                    displayName: 'File ID',
                    name: 'fileId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter File ID',
                    description: 'The unique identifier of the file',
                    displayOptions: {
                        show: {
                            resource: ['file'],
                            operation: ['get', 'delete'],
                        },
                    },
                },
                {
                    displayName: 'Operation',
                    name: 'operation',
                    type: 'options',
                    noDataExpression: true,
                    displayOptions: {
                        show: {
                            resource: ['company'],
                        },
                    },
                    options: [
                        {
                            name: 'Create Project',
                            value: 'createProject',
                            description: 'Create a new project under the company',
                            action: 'Create a project under the company',
                        },
                        {
                            name: 'Create Workflow',
                            value: 'createWorkflow',
                            description: 'Create a new workflow under a company project',
                            action: 'Create a workflow under a company project',
                        },
                        {
                            name: 'Delete',
                            value: 'delete',
                            description: 'Delete the company',
                            action: 'Delete the company',
                        },
                        {
                            name: 'Get',
                            value: 'get',
                            description: 'Get company details',
                            action: 'Get company details',
                        },
                        {
                            name: 'Get Projects',
                            value: 'getProjects',
                            description: 'Get all projects for the company',
                            action: 'Get company projects',
                        },
                        {
                            name: 'Get Workflows',
                            value: 'getWorkflows',
                            description: 'Get all workflows for a company project',
                            action: 'Get workflows for a company project',
                        },
                        {
                            name: 'Update',
                            value: 'update',
                            description: 'Update company details',
                            action: 'Update the company',
                        },
                    ],
                    default: 'get',
                },
                {
                    displayName: 'Company ID',
                    name: 'companyId',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter Company ID (or leave empty to use credential)',
                    description: 'The company ID. If left empty, uses the Company ID from credentials.',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                        },
                    },
                },
                {
                    displayName: 'Project ID',
                    name: 'companyProjectId',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter Project ID',
                    description: 'The project ID within the company',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['getWorkflows', 'createWorkflow'],
                        },
                    },
                },
                {
                    displayName: 'Name',
                    name: 'companyUpdateName',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter new company name',
                    description: 'New name for the company',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Description',
                    name: 'companyUpdateDescription',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter company description',
                    description: 'New description for the company',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['update'],
                        },
                    },
                },
                {
                    displayName: 'Project Name',
                    name: 'companyProjectName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter project name',
                    description: 'Name for the new project',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createProject'],
                        },
                    },
                },
                {
                    displayName: 'Project Description',
                    name: 'companyProjectDescription',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter project description',
                    description: 'Description for the new project',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createProject'],
                        },
                    },
                },
                {
                    displayName: 'Project Status',
                    name: 'companyProjectStatus',
                    type: 'options',
                    default: 'active',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Status for the new project',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createProject'],
                        },
                    },
                },
                {
                    displayName: 'Workflow Name',
                    name: 'companyWorkflowName',
                    type: 'string',
                    default: '',
                    required: true,
                    placeholder: 'Enter workflow name',
                    description: 'Name for the new workflow',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createWorkflow'],
                        },
                    },
                },
                {
                    displayName: 'Workflow Description',
                    name: 'companyWorkflowDescription',
                    type: 'string',
                    default: '',
                    placeholder: 'Enter workflow description',
                    description: 'Description for the new workflow',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createWorkflow'],
                        },
                    },
                },
                {
                    displayName: 'Workflow Status',
                    name: 'companyWorkflowStatus',
                    type: 'options',
                    default: 'draft',
                    options: [
                        {
                            name: 'Active',
                            value: 'active',
                        },
                        {
                            name: 'Draft',
                            value: 'draft',
                        },
                        {
                            name: 'Inactive',
                            value: 'inactive',
                        },
                    ],
                    description: 'Status for the new workflow',
                    displayOptions: {
                        show: {
                            resource: ['company'],
                            operation: ['createWorkflow'],
                        },
                    },
                },
            ],
        };
    }
    async execute() {
        const items = this.getInputData();
        const returnData = [];
        const baseUrl = 'https://app.agentic-hub.ai/api/v1';
        for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
            try {
                const credentials = await this.getCredentials('agenticHubApi');
                const resource = this.getNodeParameter('resource', itemIndex);
                const operation = this.getNodeParameter('operation', itemIndex);
                let response;
                const options = {
                    url: '',
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json',
                        Accept: 'application/json',
                    },
                    json: true,
                    timeout: 30000,
                };
                if (resource === 'project') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/projects`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('name', itemIndex);
                        const description = this.getNodeParameter('description', itemIndex, '');
                        const status = this.getNodeParameter('status', itemIndex, 'active');
                        options.method = 'POST';
                        options.url = `${baseUrl}/projects`;
                        options.body = {
                            name,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                    else if (operation === 'get') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/projects/${projectId}`;
                    }
                    else if (operation === 'update') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        const name = this.getNodeParameter('updateName', itemIndex, '');
                        const description = this.getNodeParameter('description', itemIndex, '');
                        const status = this.getNodeParameter('status', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/projects/${projectId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (description)
                            body.description = description;
                        if (status)
                            body.status = status;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const projectId = this.getNodeParameter('projectId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/projects/${projectId}`;
                    }
                }
                else if (resource === 'workflow') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/workflows`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('workflowName', itemIndex);
                        const projectId = this.getNodeParameter('workflowProjectId', itemIndex);
                        const description = this.getNodeParameter('workflowDescription', itemIndex, '');
                        const status = this.getNodeParameter('workflowStatus', itemIndex, 'active');
                        options.method = 'POST';
                        options.url = `${baseUrl}/workflows`;
                        options.body = {
                            name,
                            projectId,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                    else if (operation === 'get') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                    }
                    else if (operation === 'update') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        const name = this.getNodeParameter('workflowUpdateName', itemIndex, '');
                        const description = this.getNodeParameter('workflowDescription', itemIndex, '');
                        const status = this.getNodeParameter('workflowStatus', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (description)
                            body.description = description;
                        if (status)
                            body.status = status;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/workflows/${workflowId}`;
                    }
                    else if (operation === 'sendMessage') {
                        const workflowId = this.getNodeParameter('workflowId', itemIndex);
                        const sessionId = this.getNodeParameter('sendMessageSessionId', itemIndex);
                        const content = this.getNodeParameter('sendMessageContent', itemIndex);
                        const direction = this.getNodeParameter('sendMessageDirection', itemIndex);
                        const convOptions = this.getNodeParameter('sendMessageConversationOptions', itemIndex, {});
                        const msgOptions = this.getNodeParameter('sendMessageOptions', itemIndex, {});
                        options.method = 'POST';
                        options.url = `${baseUrl}/workflows/${workflowId}/conversations-with-message`;
                        const conversation = {
                            sessionid: sessionId,
                        };
                        if (convOptions.ipAddress)
                            conversation.ipAddress = convOptions.ipAddress;
                        if (convOptions.phoneNumber)
                            conversation.phoneNumber = convOptions.phoneNumber;
                        if (convOptions.lastContext)
                            conversation.lastContext = convOptions.lastContext;
                        if (convOptions.requiresHumanAttention !== undefined)
                            conversation.requiresHumanAttention = convOptions.requiresHumanAttention;
                        if (convOptions.isHandledByHuman !== undefined)
                            conversation.isHandledByHuman = convOptions.isHandledByHuman;
                        if (convOptions.status !== undefined)
                            conversation.status = convOptions.status;
                        if (convOptions.overallSentiment !== undefined)
                            conversation.overallSentiment = convOptions.overallSentiment;
                        if (convOptions.orderId !== undefined)
                            conversation.orderId = convOptions.orderId;
                        const message = {
                            content,
                            direction,
                        };
                        if (msgOptions.templateId)
                            message.templateId = msgOptions.templateId;
                        if (msgOptions.errorMessage)
                            message.errorMessage = msgOptions.errorMessage;
                        if (msgOptions.messageSid)
                            message.messageSid = msgOptions.messageSid;
                        if (msgOptions.sentimentScore !== undefined)
                            message.sentimentScore = msgOptions.sentimentScore;
                        if (msgOptions.status !== undefined)
                            message.status = msgOptions.status;
                        options.body = { conversation, message };
                    }
                }
                else if (resource === 'agent') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/agents`;
                    }
                    else if (operation === 'create') {
                        const name = this.getNodeParameter('agentName', itemIndex);
                        const workflowId = this.getNodeParameter('agentWorkflowId', itemIndex);
                        const mainPrompt = this.getNodeParameter('mainPrompt', itemIndex);
                        const dynamicFieldsStr = this.getNodeParameter('dynamicFields', itemIndex, '[]');
                        const isActive = this.getNodeParameter('isActive', itemIndex, true);
                        let dynamicFields = [];
                        try {
                            dynamicFields = JSON.parse(dynamicFieldsStr);
                        }
                        catch (e) {
                            dynamicFields = [];
                        }
                        options.method = 'POST';
                        options.url = `${baseUrl}/agents`;
                        options.body = {
                            name,
                            workflowId,
                            mainPrompt,
                            ...(dynamicFields.length > 0 && { dynamicFields }),
                            isActive,
                        };
                    }
                    else if (operation === 'get') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/agents/${agentId}`;
                    }
                    else if (operation === 'update') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        const name = this.getNodeParameter('agentUpdateName', itemIndex, '');
                        const mainPrompt = this.getNodeParameter('updateMainPrompt', itemIndex, '');
                        const dynamicFieldsStr = this.getNodeParameter('dynamicFields', itemIndex, '');
                        const isActive = this.getNodeParameter('isActive', itemIndex, undefined);
                        options.method = 'PUT';
                        options.url = `${baseUrl}/agents/${agentId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (mainPrompt)
                            body.mainPrompt = mainPrompt;
                        if (dynamicFieldsStr) {
                            try {
                                body.dynamicFields = JSON.parse(dynamicFieldsStr);
                            }
                            catch (e) {
                            }
                        }
                        if (isActive !== undefined)
                            body.isActive = isActive;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const agentId = this.getNodeParameter('agentId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/agents/${agentId}`;
                    }
                }
                else if (resource === 'content') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/content`;
                    }
                    else if (operation === 'create') {
                        const workflowId = this.getNodeParameter('contentWorkflowId', itemIndex);
                        const title = this.getNodeParameter('contentTitle', itemIndex);
                        const type = this.getNodeParameter('contentType', itemIndex);
                        options.method = 'POST';
                        options.url = `${baseUrl}/content`;
                        const body = {
                            workflowId,
                            title,
                            type,
                        };
                        if (type === 'text') {
                            const content = this.getNodeParameter('contentText', itemIndex);
                            body.content = content;
                        }
                        else if (type === 'faq') {
                            const faqItemsStr = this.getNodeParameter('faqItems', itemIndex);
                            try {
                                body.faqItems = JSON.parse(faqItemsStr);
                            }
                            catch (e) {
                                throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid FAQ items JSON format', {
                                    itemIndex,
                                });
                            }
                        }
                        options.body = body;
                    }
                    else if (operation === 'get') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/content/${contentId}`;
                    }
                    else if (operation === 'update') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        const title = this.getNodeParameter('contentUpdateTitle', itemIndex, '');
                        const content = this.getNodeParameter('contentUpdateText', itemIndex, '');
                        const faqItemsStr = this.getNodeParameter('updateFaqItems', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/content/${contentId}`;
                        const body = {};
                        if (title)
                            body.title = title;
                        if (content)
                            body.content = content;
                        if (faqItemsStr) {
                            try {
                                body.faqItems = JSON.parse(faqItemsStr);
                            }
                            catch (e) {
                                throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid FAQ items JSON format', {
                                    itemIndex,
                                });
                            }
                        }
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        const contentId = this.getNodeParameter('contentId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/content/${contentId}`;
                    }
                }
                else if (resource === 'conversation') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/conversations`;
                    }
                    else if (operation === 'create') {
                        const sessionId = this.getNodeParameter('sessionId', itemIndex);
                        const workflowId = this.getNodeParameter('conversationWorkflowId', itemIndex);
                        const ipAddress = this.getNodeParameter('ipAddress', itemIndex, '');
                        const phoneNumber = this.getNodeParameter('phoneNumber', itemIndex, '');
                        options.method = 'POST';
                        options.url = `${baseUrl}/conversations`;
                        options.body = {
                            sessionId,
                            workflowId,
                            ...(ipAddress && { ipAddress }),
                            ...(phoneNumber && { phoneNumber }),
                        };
                    }
                    else if (operation === 'get') {
                        const conversationId = this.getNodeParameter('conversationId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/conversations/${conversationId}`;
                    }
                    else if (operation === 'update') {
                        const conversationId = this.getNodeParameter('conversationId', itemIndex);
                        const status = this.getNodeParameter('conversationStatus', itemIndex, undefined);
                        const requiresHumanAttention = this.getNodeParameter('requiresHumanAttention', itemIndex, undefined);
                        const isHandledByHuman = this.getNodeParameter('isHandledByHuman', itemIndex, undefined);
                        const lastContext = this.getNodeParameter('lastContext', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${baseUrl}/conversations/${conversationId}`;
                        const body = {};
                        if (status !== undefined)
                            body.status = status;
                        if (requiresHumanAttention !== undefined)
                            body.requiresHumanAttention = requiresHumanAttention;
                        if (isHandledByHuman !== undefined)
                            body.isHandledByHuman = isHandledByHuman;
                        if (lastContext)
                            body.lastContext = lastContext;
                        options.body = body;
                    }
                }
                else if (resource === 'message') {
                    if (operation === 'getAll') {
                        const conversationId = this.getNodeParameter('messageConversationId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/messages?conversationId=${conversationId}`;
                    }
                    else if (operation === 'create') {
                        const mode = this.getNodeParameter('mode', itemIndex, 'unified');
                        const content = this.getNodeParameter('messageContent', itemIndex);
                        const direction = this.getNodeParameter('direction', itemIndex);
                        const msgOptions = this.getNodeParameter('messageOptions', itemIndex, {});
                        options.method = 'POST';
                        options.url = `${baseUrl}/messages`;
                        const messageBody = {
                            content,
                            direction,
                        };
                        if (msgOptions.messageSid)
                            messageBody.messageSid = msgOptions.messageSid;
                        if (msgOptions.sentimentScore !== undefined)
                            messageBody.sentimentScore = msgOptions.sentimentScore;
                        if (msgOptions.status !== undefined)
                            messageBody.status = msgOptions.status;
                        if (msgOptions.templateId)
                            messageBody.templateId = msgOptions.templateId;
                        if (msgOptions.errorMessage)
                            messageBody.errorMessage = msgOptions.errorMessage;
                        if (mode === 'unified') {
                            const sessionId = this.getNodeParameter('messageSessionId', itemIndex);
                            const workflowId = this.getNodeParameter('messageWorkflowId', itemIndex);
                            const convOptions = this.getNodeParameter('messageConversationOptions', itemIndex, {});
                            const conversation = {
                                sessionId,
                                workflowId,
                            };
                            if (convOptions.phoneNumber && convOptions.phoneNumber.trim() !== '') {
                                conversation.phoneNumber = convOptions.phoneNumber;
                            }
                            if (convOptions.status !== undefined) {
                                conversation.status = convOptions.status;
                            }
                            if (convOptions.overallSentiment !== undefined) {
                                conversation.overallSentiment = convOptions.overallSentiment;
                            }
                            if (convOptions.requiresHumanAttention !== undefined) {
                                conversation.requiresHumanAttention = convOptions.requiresHumanAttention;
                            }
                            if (convOptions.isHandledByHuman !== undefined) {
                                conversation.isHandledByHuman = convOptions.isHandledByHuman;
                            }
                            messageBody.conversation = conversation;
                        }
                        else {
                            const conversationId = this.getNodeParameter('legacyConversationId', itemIndex);
                            const sessionId = this.getNodeParameter('legacySessionId', itemIndex, '');
                            messageBody.conversationId = conversationId;
                            if (sessionId)
                                messageBody.sessionId = sessionId;
                        }
                        options.body = messageBody;
                    }
                    else if (operation === 'get') {
                        const messageId = this.getNodeParameter('messageId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/messages/${messageId}`;
                    }
                }
                else if (resource === 'file') {
                    if (operation === 'getAll') {
                        options.method = 'GET';
                        options.url = `${baseUrl}/files`;
                    }
                    else if (operation === 'get') {
                        const fileId = this.getNodeParameter('fileId', itemIndex);
                        options.method = 'GET';
                        options.url = `${baseUrl}/files/${fileId}`;
                    }
                    else if (operation === 'delete') {
                        const fileId = this.getNodeParameter('fileId', itemIndex);
                        options.method = 'DELETE';
                        options.url = `${baseUrl}/files/${fileId}`;
                    }
                }
                else if (resource === 'company') {
                    const companyBaseUrl = 'https://app.agentic-hub.ai/api/companies';
                    let companyId = this.getNodeParameter('companyId', itemIndex, '');
                    if (!companyId) {
                        companyId = credentials.companyId;
                    }
                    if (operation === 'get') {
                        options.method = 'GET';
                        options.url = `${companyBaseUrl}/${companyId}`;
                    }
                    else if (operation === 'update') {
                        const name = this.getNodeParameter('companyUpdateName', itemIndex, '');
                        const description = this.getNodeParameter('companyUpdateDescription', itemIndex, '');
                        options.method = 'PUT';
                        options.url = `${companyBaseUrl}/${companyId}`;
                        const body = {};
                        if (name)
                            body.name = name;
                        if (description)
                            body.description = description;
                        options.body = body;
                    }
                    else if (operation === 'delete') {
                        options.method = 'DELETE';
                        options.url = `${companyBaseUrl}/${companyId}`;
                    }
                    else if (operation === 'getProjects') {
                        options.method = 'GET';
                        options.url = `${companyBaseUrl}/${companyId}/projects`;
                    }
                    else if (operation === 'createProject') {
                        const name = this.getNodeParameter('companyProjectName', itemIndex);
                        const description = this.getNodeParameter('companyProjectDescription', itemIndex, '');
                        const status = this.getNodeParameter('companyProjectStatus', itemIndex, 'active');
                        options.method = 'POST';
                        options.url = `${companyBaseUrl}/${companyId}/projects`;
                        options.body = {
                            name,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                    else if (operation === 'getWorkflows') {
                        const projectId = this.getNodeParameter('companyProjectId', itemIndex);
                        options.method = 'GET';
                        options.url = `${companyBaseUrl}/${companyId}/projects/${projectId}/workflows`;
                    }
                    else if (operation === 'createWorkflow') {
                        const projectId = this.getNodeParameter('companyProjectId', itemIndex);
                        const name = this.getNodeParameter('companyWorkflowName', itemIndex);
                        const description = this.getNodeParameter('companyWorkflowDescription', itemIndex, '');
                        const status = this.getNodeParameter('companyWorkflowStatus', itemIndex, 'draft');
                        options.method = 'POST';
                        options.url = `${companyBaseUrl}/${companyId}/projects/${projectId}/workflows`;
                        options.body = {
                            name,
                            ...(description && { description }),
                            ...(status && { status }),
                        };
                    }
                }
                response = await this.helpers.httpRequestWithAuthentication.call(this, 'agenticHubApi', options);
                returnData.push({
                    json: response,
                    pairedItem: itemIndex,
                });
            }
            catch (error) {
                if (this.continueOnFail()) {
                    returnData.push({
                        json: {
                            success: false,
                            error: error.message,
                            timestamp: new Date().toISOString(),
                        },
                        error,
                        pairedItem: itemIndex,
                    });
                }
                else {
                    if (error.context) {
                        error.context.itemIndex = itemIndex;
                        throw error;
                    }
                    throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
                        itemIndex,
                    });
                }
            }
        }
        return [returnData];
    }
}
exports.AgenticHub = AgenticHub;
//# sourceMappingURL=AgenticHub.node.js.map