interface WorkflowConfig {
    description?: string;
}
type TriggerType = 'chat.started' | 'chat.ended' | 'message.received' | 'intent.detected' | 'sentiment.negative' | 'payment.failed' | 'user.signup' | 'custom.event';
type TemplateVariable = `{{${string}}}`;
interface ActionParams {
    [key: string]: any;
}
interface WorkflowAction<T = ActionParams> {
    type: string;
    params: T;
}
interface CollectFirstNameParams extends ActionParams {
    prompt: string;
    errorMessage?: string;
    maxRetries?: number;
}
interface SaveToContactParams extends ActionParams {
    field: 'firstName' | 'lastName' | 'email' | 'phone' | 'company';
    value: string | TemplateVariable;
}
interface SendMessageParams extends ActionParams {
    message: string | TemplateVariable;
    delay?: number;
}
interface SetVariableParams extends ActionParams {
    name: string;
    value: string | TemplateVariable;
}
interface ConditionalParams extends ActionParams {
    condition: string;
    trueAction: WorkflowAction;
    falseAction?: WorkflowAction;
}
interface WorkflowDefinition {
    name: string;
    config: WorkflowConfig;
    trigger: {
        type: TriggerType;
        conditions?: Record<string, any>;
    };
    actions: WorkflowAction[];
}
interface WorkflowBuilder {
    on(trigger: TriggerType): WorkflowWithTrigger;
}
interface WorkflowWithTrigger {
    use(...actions: WorkflowAction[]): WorkflowDefinition;
}

/**
 * Creates a new workflow with the specified name and optional configuration
 *
 * @example
 * ```typescript
 * import { workflow, collectFirstName, saveToContact } from "@candoa/workflows";
 *
 * export default workflow("welcome-new-user", {
 *   description: "Collects the user's first name when they start a chat"
 * })
 *   .on("chat.started")
 *   .use(
 *     collectFirstName({ prompt: "Hi! What's your first name?" }),
 *     saveToContact({ field: "firstName", value: "{{firstName}}" })
 *   );
 * ```
 *
 * @param name Unique identifier for the workflow
 * @param config Optional workflow configuration including description
 * @returns Workflow builder for chaining .on() and .use() methods
 */
declare function workflow(name: string, config?: WorkflowConfig): WorkflowBuilder;
/**
 * Type-safe helper for creating custom trigger conditions
 */
declare function createTrigger<T extends Record<string, any>>(type: TriggerType, conditions?: T): {
    type: TriggerType;
    conditions?: T;
};
/**
 * Validates a workflow definition for common issues
 * @param workflowDef The workflow definition to validate
 * @returns Array of validation errors, empty if valid
 */
declare function validateWorkflow(workflowDef: WorkflowDefinition): string[];
/**
 * Converts a workflow definition to a JSON-serializable format for storage
 * This matches the `workflowData` field structure in your database schema
 * @param workflowDef The workflow definition to serialize
 * @returns JSON-safe object ready for database storage in the `workflowData` field
 */
declare function serializeWorkflow(workflowDef: WorkflowDefinition): Record<string, any>;

interface WorkflowData {
    name: string;
    description?: string;
    trigger: {
        type: 'chat.started' | 'chat.ended' | 'message.received' | 'intent.detected' | 'sentiment.negative' | 'payment.failed' | 'user.signup' | 'custom.event';
        conditions?: Record<string, any>;
    };
    actions: Array<{
        type: string;
        params: Record<string, any>;
    }>;
    metadata: {
        version: string;
        enabled: boolean;
        sdk_version: string;
        triggers_count: number;
        actions_count: number;
        last_executed: string | null;
        execution_count: number;
        success_count: number;
        error_count: number;
        integrations: {
            handoff: boolean;
            contacts: boolean;
            conversations: boolean;
            tasks: boolean;
            emails: boolean;
        };
        access_levels: string[];
        created_at: string;
    };
}
/**
 * Prepares workflow data for insertion into the database
 * Matches the schema: workflows table with workflowData JSON field
 */
declare function prepareWorkflowForDatabase(workflowDef: WorkflowDefinition, projectId: string): {
    name: string;
    workflowData: WorkflowData;
    projectId: string;
};
/**
 * Extract workflow execution context from conversation and contact data
 * This provides the template variables for workflow execution
 */
declare function buildWorkflowContext(params: {
    conversationId?: string;
    contactData?: {
        id?: string;
        name?: string;
        email?: string;
        phoneNumber?: string;
        firstName?: string;
        lastName?: string;
        company?: string;
    };
    messageHistory?: Array<{
        role: string;
        content: string;
        createdAt: Date;
    }>;
    triggerData?: Record<string, any>;
}): Record<string, any>;
/**
 * Validate that a workflow is compatible with Candoa's systems
 */
declare function validateWorkflowCompatibility(workflowDef: WorkflowDefinition): {
    isValid: boolean;
    warnings: string[];
    errors: string[];
};
/**
 * Extract metrics from workflow execution for analytics
 */
declare function extractWorkflowMetrics(workflowDef: WorkflowDefinition, executionResult: {
    success: boolean;
    error?: string;
    executionTime: number;
    actionsCompleted: number;
}): {
    workflow_name: string;
    trigger_type: string;
    actions_count: number;
    actions_completed: number;
    execution_time_ms: number;
    success: boolean;
    error?: string;
    timestamp: string;
};
/**
 * Helper to update workflow execution statistics in the database
 */
declare function updateWorkflowStats(currentWorkflowData: WorkflowData, wasSuccessful: boolean): WorkflowData;

/**
 * Collects the user's first name with a custom prompt
 * @param params Configuration for collecting first name
 * @returns Workflow action for collecting first name
 */
declare function collectFirstName(params: CollectFirstNameParams): WorkflowAction;
/**
 * Collects the user's last name with a custom prompt
 */
declare function collectLastName(params: {
    prompt: string;
    errorMessage?: string;
    maxRetries?: number;
}): WorkflowAction;
/**
 * Collects the user's email address with validation
 */
declare function collectEmail(params: {
    prompt: string;
    errorMessage?: string;
    maxRetries?: number;
}): WorkflowAction;
/**
 * Saves data to a contact field
 * @param params Field and value to save
 * @returns Workflow action for saving to contact
 */
declare function saveToContact(params: SaveToContactParams): WorkflowAction;
/**
 * Sends a message to the user
 * @param params Message content and optional delay
 * @returns Workflow action for sending message
 */
declare function sendMessage(params: SendMessageParams): WorkflowAction;
/**
 * Sets a workflow variable for later use
 * @param params Variable name and value
 * @returns Workflow action for setting variable
 */
declare function setVariable(params: SetVariableParams): WorkflowAction;
/**
 * Creates a conditional action based on a condition
 * @param params Condition and actions to execute
 * @returns Workflow action for conditional logic
 */
declare function conditional(params: ConditionalParams): WorkflowAction;
/**
 * Waits for a specified amount of time
 */
declare function wait(params: {
    duration: number;
    unit?: 'seconds' | 'minutes' | 'hours';
}): WorkflowAction;
/**
 * Triggers a handoff to human agent
 */
declare function handoffToHuman(params: {
    reason?: string;
}): WorkflowAction;
/**
 * Sends an email notification
 */
declare function sendEmail(params: {
    to: string;
    subject: string;
    body: string;
    template?: string;
}): WorkflowAction;
/**
 * Creates a task or ticket in the system
 */
declare function createTask(params: {
    title: string;
    description?: string;
    assignee?: string;
}): WorkflowAction;
/**
 * Adds tags to the conversation or contact
 */
declare function addTags(params: {
    tags: string[];
    target?: 'conversation' | 'contact';
}): WorkflowAction;

declare const version = "0.1.0";
declare const name = "@candoa/workflows";

export { type ActionParams, type CollectFirstNameParams, type ConditionalParams, type SaveToContactParams, type SendMessageParams, type SetVariableParams, type TemplateVariable, type TriggerType, type WorkflowAction, type WorkflowBuilder, type WorkflowConfig, type WorkflowData, type WorkflowDefinition, type WorkflowWithTrigger, addTags, buildWorkflowContext, collectEmail, collectFirstName, collectLastName, conditional, createTask, createTrigger, extractWorkflowMetrics, handoffToHuman, name, prepareWorkflowForDatabase, saveToContact, sendEmail, sendMessage, serializeWorkflow, setVariable, updateWorkflowStats, validateWorkflow, validateWorkflowCompatibility, version, wait, workflow };
