import { EventEmitter } from 'stream';

type GanttChartArgs = {
    unit?: 'ms' | 's';
    minHeight?: number;
    minWidth?: number;
};
type TimeSpan = {
    key: string;
    startTs: number;
    endTs?: number;
};
type GraphItem = {
    descriptor: string;
    label?: string;
};
/**
 * Generates a URL for an execution graph visualization using QuickChart's GraphViz service.
 *
 * @param {GraphItem[]} graphItems - Array of graph items to visualize.
 * @returns {string} A URL that can be used to display the execution graph.
 */
declare function generateExecutionGraphQuickchart(graphItems: GraphItem[]): string;
/**
 * Generates a Gantt chart as a PNG image using the QuickChart API.
 *
 * This function converts an array of time spans into a horizontal bar chart
 * representation and returns the chart as a binary buffer.
 */
declare function generateGanttChartQuickchart(timeSpans: TimeSpan[], args?: GanttChartArgs): Promise<Buffer>;
/**
 * Generates an HTML page containing a Google Gantt Chart visualization.
 */
declare function generateGanttChartGoogle(timeSpans: TimeSpan[], args?: GanttChartArgs): string;

type TimeMeta = {
    startTs: number;
    endTs?: number;
    timeUsageMs?: number;
};
type StepMeta = {
    name: string;
    key: string;
    time: TimeMeta;
    records: Record<string, any>;
    result?: any;
    error?: string;
};
type NestedStepMeta = StepMeta & {
    substeps: NestedStepMeta[];
};
type StepEvents = 'step-start' | 'step-success' | 'step-error' | 'step-record' | 'step-complete';
type StepGanttArg = GanttChartArgs & {
    filter?: RegExp | string[];
};
type RecordListener = (key: string, data: any, stepMeta?: StepMeta) => void | Promise<void>;
type StepStartListener = (key: string, stepMeta?: StepMeta) => void | Promise<void>;
type StepSuccessListener = (key: string, result: any, stepMeta?: StepMeta) => void | Promise<void>;
type StepErrorListener = (key: string, error: Error, stepMeta?: StepMeta) => void | Promise<void>;
type StepCompleteListener = (key: string, stepMeta?: StepMeta) => void | Promise<void>;
type StepRecordListener = (key: string, recordKey: string, data: any, stepMeta?: StepMeta) => void | Promise<void>;
declare class Step {
    protected name: string;
    protected key: string;
    protected result?: any;
    protected error?: Error;
    protected records: Record<string, any>;
    protected time: TimeMeta;
    protected parent: Step | null;
    protected ctx: Step;
    protected steps: Array<Step>;
    protected eventEmitter: EventEmitter;
    constructor(name: string, options?: {
        parent?: Step;
        key?: string;
        eventEmitter?: EventEmitter;
    });
    track<T = any>(callable: (st: Step) => Promise<T>): Promise<T>;
    getName(): string;
    getKey(): string;
    /**
     * This method output a nested array of step meta, only includes the meta of the current step.
     */
    getStepMeta(): StepMeta;
    protected run(callable: (st: Step) => Promise<any>): Promise<any>;
    /**
     * Create a new step and run it.
     */
    step<T>(name: string, callable: (st: Step) => Promise<T>): Promise<T>;
    /**
     * @deprecated
     */
    log(key: string, data: any): Promise<this>;
    record(recordKey: string, data: any): Promise<this>;
    on(key: 'step-start', listener: StepStartListener): this;
    on(key: 'step-success', listener: StepSuccessListener): this;
    on(key: 'step-error', listener: StepErrorListener): this;
    on(key: 'step-record', listener: StepRecordListener): this;
    on(key: 'step-complete', listener: StepCompleteListener): this;
    /**
     * @deprecated Use `outputNested()` instead.
     */
    outputHierarchy(): NestedStepMeta;
    /**
     * This method output a nested array of step meta, including it own meta and its substeps' meta.
     */
    outputNested(): NestedStepMeta;
    /**
     * This method output a flattened array of step meta, including it own meta and its substeps' meta.
     */
    outputFlattened(): StepMeta[];
    getRecords(): Record<string, any>;
    getTimeMeta(): TimeMeta;
    /**
     * @deprecated Use `getTimeMeta()` instead.
     */
    getTime(): TimeMeta;
    /**
     * Generate a execution graph via QuickChart.io, returning an quickchart URL.
     */
    _executionGraphQuickchart(): string;
    private static getGanttSpans;
    /**
     * Generate a Gantt chart via QuickChart.io, returning a PNG buffer generated by quickchart.
     */
    ganttQuickchart(args?: StepGanttArg): Promise<Buffer>;
    /**
     * Generate a Gantt chart via QuickChart.io, returning a PNG buffer generated by quickchart.
     */
    static ganttQuickChart(steps: StepMeta[], args?: StepGanttArg): Promise<Buffer>;
    /**
     * Generate a Gantt chart locally via ChartJS, returning a string of HTML.
     */
    ganttGoogleChartHtml(args?: StepGanttArg): string;
    /**
     * Generate a Gantt chart locally via ChartJS, returning a string of HTML.
     */
    static ganttGoogleChartHtml(steps: StepMeta[], args?: StepGanttArg): string;
    static flattenNestedStepMetas(root: NestedStepMeta): StepMeta[];
}

interface Transport {
    initiateRun(pipelineMeta: PipelineMeta): Promise<void>;
    finishRun(pipelineMeta: PipelineMeta, status: 'completed' | 'failed' | 'running'): Promise<void>;
    initiateStep(runId: string, step: StepMeta): Promise<void>;
    finishStep(runId: string, step: StepMeta): Promise<void>;
}

interface HttpTransportOptions {
    baseUrl: string;
    batchLogs?: boolean;
    flushInterval?: number;
    maxBatchSize?: number;
    debug?: boolean;
    maxRetries?: number;
}
declare class HttpTransport implements Transport {
    private baseUrl;
    private headers;
    private batchLogs;
    private flushInterval;
    private maxBatchSize;
    private debug;
    private maxRetries;
    private eventCache;
    private timer;
    private activeFlushes;
    constructor(options: HttpTransportOptions);
    private startFlushTimer;
    private stopFlushTimer;
    private delay;
    private sendEventsWithRetry;
    private flushEvents;
    private flushIfCacheFull;
    initiateRun(pipelineMeta: PipelineMeta): Promise<void>;
    finishRun(pipelineMeta: PipelineMeta, status: 'completed' | 'failed' | 'running'): Promise<void>;
    initiateStep(runId: string, step: StepMeta): Promise<void>;
    finishStep(runId: string, step: StepMeta): Promise<void>;
    flushAndStop(): Promise<void>;
}

type PipelineMeta = StepMeta & {
    logVersion: number;
    runId: string;
    steps: StepMeta[];
};
declare class Pipeline extends Step {
    private runId;
    /**
     * 'real_time' = save as soon as a step has status change
     * 'finish' = save only on pipeline run completion
     * 'off' = no auto saving
     */
    private autoSave;
    private transport?;
    constructor(name: string, options?: {
        runId?: string;
        autoSave?: 'real_time' | 'finish' | 'off';
        transport?: Transport;
    });
    getRunId(): string;
    outputPipelineMeta(): PipelineMeta;
}

/**
 * This decorator wraps the method as a substep of the parent step.
 * The parent step must be passed as the last argument of the method.
 *
 * Note: The `Step` instance that the callee method received is a Substep.
 */
declare function WithStep(stepName: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;

export { type GanttChartArgs, type GraphItem, HttpTransport, type HttpTransportOptions, type NestedStepMeta, Pipeline, type PipelineMeta, type RecordListener, Step, type StepCompleteListener, type StepErrorListener, type StepEvents, type StepGanttArg, type StepMeta, type StepRecordListener, type StepStartListener, type StepSuccessListener, type TimeMeta, type TimeSpan, type Transport, WithStep, generateExecutionGraphQuickchart, generateGanttChartGoogle, generateGanttChartQuickchart };
