import type { KyooQueue } from './queue';
import type { KyooClient } from './adapters';
import type { Debugger } from './utils/debug';
import type { Serializable } from '@nhtio/serialization/types';
import type { KyooQueueToWorkerBus } from './utils/queue_to_worker_bus';
import type { KyooJob, KyooJobAck, KyooJobNack, KyooWorkable } from './job';
import type { KyooWorkerToApplicationEventEmitterKey as Key, KyooWorkerToApplicationEventEmitterListener as Listener } from './utils/worker_to_application_event_emitter';
/**
 * Describes the shape of the object that is passed to the job processor function.
 */
export interface KyooJobMessage<M = Serializable> {
    /**
     * The job object.
     */
    job: KyooJob<M>;
    /**
     * The number of attempts made to process the job.
     */
    attempts: number;
    /**
     * The name of the queue from which the job was fetched.
     */
    queue: string;
    /**
     * The name of the worker that processed the job.
     */
    worker: string;
}
/**
 * An object containing the dispositioners for the job.
 */
export interface KyooWorkerDispositioners {
    /**
     * A function which acknowledges the job.
     * @see {@link KyooJobAck}
     */
    ack: KyooJobAck;
    /**
     * A function which negatively acknowledges the job.
     * @see {@link KyooJobNack}
     */
    nack: KyooJobNack;
}
/**
 * An object containing the controls for the worker.
 * @remarks These controls can be used from inside the job processor to pause or resume the worker
 * without having to exit the scope of the job processor.
 * @since 1.20240407.0
 */
export interface KyooWorkerControls {
    /**
     * A function which pauses the worker.
     */
    pause: () => Promise<void>;
    /**
     * A function which resumes the worker.
     */
    resume: () => Promise<void>;
}
/**
 * Describes the shape of a function which is used in the KyooWorker class to process jobs.
 */
export interface KyooJobProcessor<M = Serializable> {
    (
    /**
     * The job message object.
     */
    message: KyooJobMessage<M>, 
    /**
     * An object containing the dispositioners for the job.
     */
    dispositioners: KyooWorkerDispositioners, 
    /**
     * An AbortSignal which is called when the job should be aborted.
     */
    signal: AbortSignal, 
    /**
     * An object containing the controls for the worker.
     * @since 1.20240407.0
     */
    controls: KyooWorkerControls): Promise<void>;
}
interface KyooQueueJobFetcher<M = Serializable> {
    (onDispositioned?: (disposition: 'ack' | 'nack') => void): Promise<KyooWorkable<M> | undefined>;
}
/**
 * The class responsible for receiving and processing jobs from a queue. A worker can be created by using {@link KyooQueue.worker}.
 * @remarks
 * While it is possible to retrieve jobs directly from the queue, this is the preferred method for
 * creating conumer workers which process jobs in a consistent manner.
 * @template T - The type of the Queue Broker client. Options are `amqp`, `bullmq` and `sqs`.
 * @template M - The type of the job payload. This is a generic type which extends `KyooSerializable`.
 */
export declare class KyooWorker<T extends KyooClient, M = Serializable> {
    #private;
    /**
     * @private
     */
    constructor(queue: KyooQueue<T>, name: string, bus: KyooQueueToWorkerBus, dbgr: Debugger, processor: KyooJobProcessor<M>, noAck: boolean | undefined, autostart: boolean | undefined, blocking: boolean | undefined, fetcher: KyooQueueJobFetcher<M>);
    /**
     * The name of the worker.
     */
    get name(): string;
    /**
     * Indicates whether the worker is running or not.
     */
    get running(): boolean;
    /**
     * Indicates whether the worker has been terminated or not.
     */
    get terminated(): boolean;
    /**
     * Starts or Resumes processing jobs.
     */
    resume(): Promise<void>;
    /**
     * Pauses / Stops processing jobs.
     */
    pause(): Promise<void>;
    /**
     * Manually process next jobs using the worker's processor function.
     * @param count The number of jobs to process. If `count` is less than or equal to 0, the method will return immediately.
     * @param signal An optional AbortSignal to abort fetching jobs to be processed and processing jobs where possible.
     */
    processNext(count?: number, signal?: AbortSignal): Promise<boolean>;
    /**
     * Alias for `KyooWorker.on(eventName, listener)`.
     */
    addListener<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Alias for `KyooWorker.removeListener()`.
     */
    off<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Adds the `listener` function to the end of the listeners array for the event
     * named `eventName`. No checks are made to see if the `listener` has already
     * been added. Multiple calls passing the same combination of `eventName` and
     * `listener` will result in the `listener` being added, and called, multiple times.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     *
     * By default, event listeners are invoked in the order they are added. The `KyooWorker.prependListener()` method can be used as an alternative to add the
     * event listener to the beginning of the listeners array.
     *
     * @param eventName The name of the event.
     * @param listener The callback function
     */
    on<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Adds a **one-time** `listener` function for the event named `eventName`. The
     * next time `eventName` is triggered, this listener is removed and then invoked.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     *
     * By default, event listeners are invoked in the order they are added. The `KyooWorker.prependOnceListener()` method can be used as an alternative to add the
     * event listener to the beginning of the listeners array.
     *
     * @param eventName The name of the event.
     * @param listener The callback function
     */
    once<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Adds the `listener` function to the _beginning_ of the listeners array for the
     * event named `eventName`. No checks are made to see if the `listener` has
     * already been added. Multiple calls passing the same combination of `eventName`
     * and `listener` will result in the `listener` being added, and called, multiple times.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     * @param eventName The name of the event.
     * @param listener The callback function
     */
    prependListener<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this
     * listener is removed, and then invoked.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     * @param eventName The name of the event.
     * @param listener The callback function
     */
    prependOnceListener<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * Removes all listeners, or those of the specified `eventName`.
     *
     * It is bad practice to remove listeners added elsewhere in the code,
     * particularly when the `KyooWorker` instance was created by some other
     * component or module.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     */
    removeAllListeners<K extends Key>(eventName?: K): this;
    /**
     * Removes the specified `listener` from the listener array for the event named `eventName`.
     *
     * `removeListener()` will remove, at most, one instance of a listener from the
     * listener array. If any single listener has been added multiple times to the
     * listener array for the specified `eventName`, then `removeListener()` must be
     * called multiple times to remove each instance.
     *
     * Once an event is emitted, all listeners attached to it at the
     * time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
     * will not remove them from`emit()` in progress. Subsequent events behave as expected.
     *
     * Because listeners are managed using an internal array, calling this will
     * change the position indices of any listener registered _after_ the listener
     * being removed. This will not impact the order in which listeners are called.
     *
     * When a single function has been added as a handler multiple times for a single
     * event, `removeListener()` will remove the most
     * recently added instance.
     *
     * Returns a reference to the `KyooWorker`, so that calls can be chained.
     */
    removeListener<K extends Key>(eventName: K, listener: Listener<K>): this;
    /**
     * The version of the library
     * @returns The version of the library
     */
    get version(): string;
    /**
     * The version of the library
     * @returns The version of the library
     */
    static get version(): string;
}
/**
 * Checks if the given object is an instance of KyooWorker
 * @param obj The object to check
 * @returns A boolean indicating if the object is a KyooWorker
 * @remarks This is needed since the KyooWorker class is not exported from the module
 */
export declare const isAKyooWorker: (obj: unknown) => boolean;
export {};
