import { ModuleContext, CollectionEntityDefinition, SingleEntityDefinition, PluginManifest } from '@gzl10/nexus-sdk';

/**
 * Types for the remote module (SSH host management)
 */
/** Auth methods for SSH connections */
type AuthMethod = 'credential' | 'default_key' | 'agent';
/** Host connection statuses */
type HostStatus = 'unknown' | 'online' | 'offline' | 'error';
/** Credential types */
type CredentialType = 'key_pair' | 'password';
/** Script interpreters */
type InterpreterType = 'bash' | 'sh' | 'python' | 'node' | 'custom';
/** Execution statuses */
type ExecutionStatus = 'success' | 'error' | 'timeout' | 'cancelled';
/** Execution trigger sources */
type TriggerSource = 'user' | 'schedule';
/** Resolved SSH connection config */
interface SSHConfig {
    host: string;
    port: number;
    username: string;
    privateKey?: string;
    passphrase?: string;
    password?: string;
    agent?: string;
    readyTimeout: number;
}
/** Execution options */
interface ExecOptions {
    timeout?: number;
    triggeredBy?: TriggerSource;
    triggeredById?: string;
}
/** Execution result */
interface ExecResult {
    exitCode: number | null;
    stdout: string;
    stderr: string;
    durationMs: number;
    status: ExecutionStatus;
}
/** Test connection result */
interface TestResult {
    success: boolean;
    fingerprint?: string;
    error?: string;
    durationMs: number;
}
/** Host record from DB */
interface RemoteHost {
    id: string;
    name: string;
    hostname: string;
    port: number;
    username: string;
    auth_method: AuthMethod;
    credential_id: string | null;
    tags: string | null;
    status: HostStatus;
    last_seen: string | null;
    fingerprint: string | null;
    notes: string | null;
    created_at: string;
    updated_at: string;
    created_by: string | null;
    updated_by: string | null;
}
/** Credential record from DB */
interface RemoteCredential {
    id: string;
    name: string;
    type: CredentialType;
    private_key: string | null;
    public_key: string | null;
    passphrase: string | null;
    password: string | null;
    notes: string | null;
    created_at: string;
    updated_at: string;
    created_by: string | null;
    updated_by: string | null;
}
/** Script record from DB */
interface RemoteScript {
    id: string;
    name: string;
    description: string | null;
    content: string;
    interpreter: InterpreterType;
    tags: string | null;
    timeout: number;
    created_at: string;
    updated_at: string;
    created_by: string | null;
    updated_by: string | null;
}
/** Remote settings (stored in single_records) */
interface RemoteSettings {
    default_user: string;
    default_port: number;
    default_timeout: number;
    private_key: string | null;
    public_key: string | null;
}

/**
 * RemoteService — SSH connection management and remote command execution
 */

declare class RemoteService {
    private readonly ctx;
    private readonly db;
    private readonly logger;
    private readonly generateId;
    private readonly crypto;
    private readonly errors;
    private readonly safeJsonParse;
    constructor(ctx: ModuleContext);
    /**
     * Executes a command on a remote host via SSH.
     */
    execute(hostId: string, command: string, options?: ExecOptions): Promise<ExecResult>;
    /**
     * Runs a saved script on a remote host.
     */
    runScript(hostId: string, scriptId: string, options?: ExecOptions): Promise<ExecResult>;
    /**
     * Tests SSH connectivity to a host.
     */
    testConnection(hostId: string): Promise<TestResult>;
    /**
     * Generates an Ed25519 SSH key pair.
     */
    generateKeypair(): Promise<{
        publicKey: string;
        privateKey: string;
    }>;
    private getHost;
    /**
     * Resolves the full SSH connection config for a host.
     */
    getConnectionConfig(host: RemoteHost): Promise<SSHConfig>;
    /**
     * Creates an SSH connection with TOFU host key verification.
     * If knownFingerprint is provided, rejects connections with mismatched keys.
     */
    private connect;
    /**
     * Executes a command on a connected SSH client.
     */
    private execCommand;
    /**
     * Logs an execution to the remote_executions event table.
     */
    private logExecution;
    /**
     * Gets remote settings via SingleService.
     */
    private getSettings;
    /**
     * Decrypts a field value. Throws on failure — never falls back to plaintext.
     */
    private decryptField;
}

/**
 * Entity definitions for the remote module
 */

declare const remoteSettingsEntity: SingleEntityDefinition;
declare const remoteCredentialsEntity: CollectionEntityDefinition;
declare const remoteHostsEntity: CollectionEntityDefinition;
declare const remoteExecutionsEntity: CollectionEntityDefinition;

/**
 * @module @gzl10/nexus-plugin-remote
 * @description SSH host management and remote execution
 */

declare const remotePlugin: PluginManifest;

export { type AuthMethod, type CredentialType, type ExecOptions, type ExecResult, type ExecutionStatus, type HostStatus, type InterpreterType, type RemoteCredential, type RemoteHost, type RemoteScript, RemoteService, type RemoteSettings, type SSHConfig, type TestResult, type TriggerSource, remotePlugin as default, remoteCredentialsEntity, remoteExecutionsEntity, remoteHostsEntity, remotePlugin, remoteSettingsEntity };
