/**
 * Docker Manager for Onebox
 *
 * Handles all Docker operations: containers, images, networks, volumes
 */
import * as plugins from '../plugins.js';
import type { IService, IContainerStats, IServiceSecretFile, IServiceVolume } from '../types.js';
interface IServiceRuntimeReferences {
    containerIds: string[];
    volumeNames: string[];
    imageName: string;
    imageReference?: string;
    imageId?: string;
}
export interface IInteractiveContainerExec {
    stream: plugins.nodeStream.Duplex;
    close: () => Promise<void>;
    inspect: () => Promise<{
        ExitCode?: number | null;
        Running?: boolean;
    }>;
}
export interface IContainerLogStreamHandle {
    close: () => void;
}
export interface IDockerLogEntry {
    source: 'stdout' | 'stderr';
    content: string;
}
export interface IDockerLogParseResult {
    entries: IDockerLogEntry[];
    remainder: Uint8Array<ArrayBufferLike>;
}
export interface IDockerLogParseOptions {
    flushRemainderAsRaw?: boolean;
}
export declare class OneboxDockerManager {
    private dockerClient;
    private networkName;
    private static logTextDecoder;
    private static logTextEncoder;
    private static readonly maxDockerLogFrameSize;
    private getFullImageName;
    private getDockerSafeName;
    private getServiceVolumeSource;
    private getStandaloneVolumeBinds;
    private getAutoManagedVolumeSourceNames;
    private listAllContainerSummaries;
    private isContainerSummaryForService;
    private inspectContainer;
    private inspectVolume;
    private isVolumeOwnedByService;
    private isVolumeUsedOutsideService;
    private removeVolume;
    private getDockerVolumeMounts;
    validateServiceSpec(serviceArg: IService): void;
    isSwarmActive(): Promise<boolean>;
    assertSecretFilesSupported(secretFilesArg: IServiceSecretFile[] | undefined): Promise<void>;
    validateServiceSecrets(serviceArg: IService, serviceSecretsArg: Record<string, string>): void;
    private resolveServiceSecretDelivery;
    private getManagedSecretName;
    private createManagedServiceSecret;
    private deleteDockerSecretById;
    removeManagedServiceSecrets(serviceNameArg: string): Promise<void>;
    private assertValidPort;
    private expandPublishedPorts;
    private isValidHostIp;
    private assertPublishedPortsAvailable;
    private assertPublishedPortsNotUsedByDocker;
    private assertPublishedPortsNotUsedByHost;
    private assertUdpPortAvailable;
    private assertTcpPortAvailable;
    private getStandalonePortConfig;
    /**
     * Initialize Docker client and create onebox network
     */
    init(): Promise<void>;
    /**
     * Release resources held by the Docker API client.
     */
    stop(): Promise<void>;
    /**
     * Ensure onebox network exists
     */
    private ensureNetwork;
    /**
     * Pull an image from a registry
     */
    pullImage(image: string, registry?: string): Promise<void>;
    getImageReference(imageArg: string, registryArg?: string): Promise<string | undefined>;
    tagImage(imageReferenceArg: string, targetImageNameArg: string): Promise<void>;
    /**
     * Create and start a container or service (depending on Swarm mode)
     */
    createContainer(service: IService, serviceSecretsArg?: Record<string, string>): Promise<string>;
    /**
     * Create a standalone container (non-Swarm mode)
     */
    private createStandaloneContainer;
    /**
     * Create a Docker Swarm service
     */
    private createSwarmService;
    /**
     * Get network ID by name
     */
    private getNetworkID;
    /**
     * Start a container or service by ID
     */
    startContainer(containerID: string): Promise<void>;
    /**
     * Start a Swarm service (scale to 1 replica)
     */
    private startService;
    /**
     * Check if ID is a service (not a container)
     */
    private isService;
    /**
     * Stop a container or service by ID
     */
    stopContainer(containerID: string): Promise<void>;
    /**
     * Stop a Swarm service (scale to 0 replicas)
     */
    private stopService;
    /**
     * Restart a container or service by ID
     */
    restartContainer(containerID: string): Promise<void>;
    /**
     * Restart a Swarm service (force update with same spec)
     */
    private restartService;
    /**
     * Remove a container or service by ID
     */
    removeContainer(containerID: string, force?: boolean, optionsArg?: {
        removeVolumes?: boolean;
    }): Promise<void>;
    /**
     * Remove a Swarm service
     */
    private removeService;
    collectServiceRuntimeReferences(serviceArg: IService): Promise<IServiceRuntimeReferences>;
    removeServiceRuntime(serviceArg: IService): Promise<IServiceRuntimeReferences>;
    removeServiceRuntimeForReplacement(serviceArg: IService, onRuntimeRemovedArg?: () => void): Promise<void>;
    private waitForServiceContainersGone;
    private removeLeftoverServiceContainers;
    removeServiceOwnedVolumes(serviceArg: IService, candidateVolumeNamesArg: string[]): Promise<string[]>;
    removeCandidateOnlyServiceVolumes(candidateServiceArg: IService, priorVolumeNamesArg: string[], candidateVolumeNamesArg: string[]): Promise<string[]>;
    removeImageIfUnused(imageNameArg: string): Promise<boolean>;
    /**
     * Get container or service status
     */
    getContainerStatus(containerID: string): Promise<string>;
    /**
     * Get Swarm service status
     */
    private getServiceStatus;
    /**
     * Get container stats (CPU, memory, network)
     * Handles both regular containers and Swarm services
     */
    getContainerStats(containerID: string): Promise<IContainerStats | null>;
    private static isDockerMissingError;
    private getContainerStatsRaw;
    /**
     * Helper: Get actual container ID for a Swarm service
     * For Swarm services, we need to find the task/container that's actually running
     */
    private getContainerIdForService;
    private static getDockerLogSource;
    private static concatenateLogBuffers;
    private static getDockerLogFrameSize;
    private static isDockerLogFrameHeader;
    static parseDockerLogFrames(bufferArg: Uint8Array<ArrayBufferLike>, optionsArg?: IDockerLogParseOptions): IDockerLogParseResult;
    static parseDockerLogText(rawLogsArg: string): IDockerLogEntry[];
    private requestDockerRaw;
    /**
     * Get container logs
     * Handles both regular containers and Swarm services
     */
    getContainerLogEntries(containerID: string, tail?: number): Promise<IDockerLogEntry[]>;
    private getContainerLogEntriesById;
    getContainerLogs(containerID: string, tail?: number): Promise<{
        stdout: string;
        stderr: string;
    }>;
    /**
     * List all onebox-managed containers
     */
    listContainers(): Promise<any[]>;
    /**
     * Check if Docker is running
     */
    isDockerRunning(): Promise<boolean>;
    /**
     * Get Docker version info
     * Note: v5 API doesn't expose version() method, so we return a placeholder
     */
    getDockerVersion(): Promise<any>;
    /**
     * Prune unused images
     */
    pruneImages(): Promise<void>;
    /**
     * Get container IP address in onebox network
     */
    getContainerIP(containerID: string): Promise<string | null>;
    /**
     * Get host port binding for a container's exposed port
     * @returns The host port number, or null if not bound
     */
    getContainerHostPort(containerID: string, containerPort: number): Promise<number | null>;
    /**
     * Execute a command in a running container
     */
    private resolveContainer;
    execInContainer(containerID: string, cmd: string[]): Promise<{
        stdout: string;
        stderr: string;
        exitCode: number;
    }>;
    startInteractiveExecInContainer(containerID: string, cmd: string[]): Promise<IInteractiveContainerExec>;
    /**
     * Create a platform service container (MongoDB, SmartStorage, etc.)
     * Platform containers are long-running infrastructure services
     */
    createPlatformContainer(options: {
        name: string;
        image: string;
        port: number;
        env: string[];
        volumes?: string[];
        volumeMounts?: IServiceVolume[];
        network: string;
        command?: string[];
        exposePorts?: number[];
        removeExistingNames?: string[];
    }): Promise<string>;
    /**
     * Get a container by ID
     * Public wrapper for Docker client method
     */
    getContainerById(containerID: string): Promise<any>;
    /**
     * List all containers
     * Public wrapper for Docker client method
     */
    listAllContainers(): Promise<any[]>;
    /**
     * Stream container logs continuously
     * @param containerID The container ID
     * @param callback Callback for each log line (line, isError)
     */
    streamContainerLogs(containerID: string, callback: (line: string, isError: boolean) => void, optionsArg?: {
        onClose?: () => void;
    }): Promise<IContainerLogStreamHandle>;
    private openContainerLogStreamById;
}
export {};
