import { RetryConfig } from '../utils/resilience.js';

/**
 * Core types for Morph Fast Apply SDK
 */

/**
 * Input parameters for the edit_file tool
 */
interface EditFileInput {
    /** Path to the file to edit (relative to baseDir) */
    target_filepath: string;
    /** First-person description of what you're changing */
    instruction: string;
    /** @deprecated Use `instruction` instead */
    instructions?: string;
    /** Lazy edit with // ... existing code ... markers */
    code_edit: string;
}
/**
 * Statistics about the changes made
 */
interface EditChanges {
    linesAdded: number;
    linesRemoved: number;
    linesModified: number;
}
/**
 * Result returned after executing an edit
 */
interface EditFileResult {
    /** Whether the edit was successful */
    success: boolean;
    /** Path to the edited file */
    filepath: string;
    /** Universal diff format showing changes */
    udiff?: string;
    /** Statistics about the changes */
    changes: EditChanges;
    /** Error message if unsuccessful */
    error?: string;
    /** Completion ID from the Morph API response */
    completionId?: string;
}
/**
 * Configuration options for the edit_file tool
 */
interface EditFileConfig {
    /** Morph API key (defaults to MORPH_API_KEY env var) */
    morphApiKey?: string;
    /** Morph API base URL */
    morphApiUrl?: string;
    /** Use morph-v3-large (default: true). Set to false to use morph-v3-fast. Defaults to MORPH_LARGE_APPLY env var. */
    large?: boolean;
    /** Base directory for file operations (defaults to cwd) */
    baseDir?: string;
    /** Whether to generate udiff (default: true) */
    generateUdiff?: boolean;
    /** Whether to automatically write to file (default: true) */
    autoWrite?: boolean;
    /** Custom system prompt (null to disable) */
    systemPrompt?: string | null;
    /** Custom tool description (defaults to EDIT_FILE_TOOL_DESCRIPTION) */
    description?: string;
    /** Timeout for API calls in ms (default: 30000) */
    timeout?: number;
    /** Retry configuration for API calls */
    retryConfig?: RetryConfig;
    /** Enable debug logging (default: false) */
    debug?: boolean;
}
/**
 * Response from Morph Apply API
 */
interface MorphApplyResponse {
    id?: string;
    choices: Array<{
        message: {
            content: string;
        };
    }>;
}
/**
 * Input for code-to-code edit (no file I/O)
 * Use this when you manage your own file system or work in a sandbox
 */
interface ApplyEditInput {
    /** The current file contents */
    originalCode: string;
    /** Lazy edit with // ... existing code ... markers */
    codeEdit: string;
    /** First-person description of what you're changing */
    instruction: string;
    /** @deprecated Use `instruction` instead */
    instructions?: string;
    /** @deprecated This parameter is accepted for backwards compatibility but does nothing. */
    filepath?: string;
}
/**
 * Configuration for applyEdit (code-to-code, no file I/O)
 */
interface ApplyEditConfig {
    /** Morph API key (defaults to MORPH_API_KEY env var) */
    morphApiKey?: string;
    /** Morph API base URL */
    morphApiUrl?: string;
    /** Use morph-v3-large (default: true). Set to false to use morph-v3-fast. Defaults to MORPH_LARGE_APPLY env var. */
    large?: boolean;
    /** Whether to generate udiff (default: true) */
    generateUdiff?: boolean;
    /** Timeout for API calls in ms (default: 30000) */
    timeout?: number;
    /** Retry configuration for API calls */
    retryConfig?: RetryConfig;
    /** Enable debug logging (default: false) */
    debug?: boolean;
}
/**
 * Result from code-to-code edit
 */
interface ApplyEditResult {
    /** Whether the edit was successful */
    success: boolean;
    /** The merged code result */
    mergedCode?: string;
    /** Universal diff format showing changes */
    udiff?: string;
    /** Statistics about the changes */
    changes: EditChanges;
    /** Error message if unsuccessful */
    error?: string;
    /** Completion ID from the Morph API response */
    completionId?: string;
}

export type { ApplyEditConfig, ApplyEditInput, ApplyEditResult, EditChanges, EditFileConfig, EditFileInput, EditFileResult, MorphApplyResponse };
