+import { EventEmitter } from 'node:events'
+import { type TransferListItem } from 'node:worker_threads'
+import type {
+ ErrorHandler,
+ ExitHandler,
+ IWorker,
+ IWorkerNode,
+ MessageHandler,
+ OnlineHandler,
+ WorkerType
+} from './worker'
+import type {
+ WorkerChoiceStrategy,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies/selection-strategies-types'
+
+/**
+ * Enumeration of pool types.
+ */
+export const PoolTypes = Object.freeze({
+ /**
+ * Fixed pool type.
+ */
+ fixed: 'fixed',
+ /**
+ * Dynamic pool type.
+ */
+ dynamic: 'dynamic'
+} as const)
+
+/**
+ * Pool type.
+ */
+export type PoolType = keyof typeof PoolTypes
+
+/**
+ * Pool events emitter.
+ */
+export class PoolEmitter extends EventEmitter {}
+
+/**
+ * Enumeration of pool events.
+ */
+export const PoolEvents = Object.freeze({
+ ready: 'ready',
+ busy: 'busy',
+ full: 'full',
+ destroy: 'destroy',
+ error: 'error',
+ taskError: 'taskError',
+ backPressure: 'backPressure'
+} as const)
+
+/**
+ * Pool event.
+ */
+export type PoolEvent = keyof typeof PoolEvents
+
+/**
+ * Pool information.
+ */
+export interface PoolInfo {
+ readonly version: string
+ readonly type: PoolType
+ readonly worker: WorkerType
+ readonly started: boolean
+ readonly ready: boolean
+ readonly strategy: WorkerChoiceStrategy
+ readonly minSize: number
+ readonly maxSize: number
+ /** Pool utilization. */
+ readonly utilization?: number
+ /** Pool total worker nodes. */
+ readonly workerNodes: number
+ /** Pool idle worker nodes. */
+ readonly idleWorkerNodes: number
+ /** Pool busy worker nodes. */
+ readonly busyWorkerNodes: number
+ readonly executedTasks: number
+ readonly executingTasks: number
+ readonly queuedTasks?: number
+ readonly maxQueuedTasks?: number
+ readonly backPressure?: boolean
+ readonly stolenTasks?: number
+ readonly failedTasks: number
+ readonly runTime?: {
+ readonly minimum: number
+ readonly maximum: number
+ readonly average?: number
+ readonly median?: number
+ }
+ readonly waitTime?: {
+ readonly minimum: number
+ readonly maximum: number
+ readonly average?: number
+ readonly median?: number
+ }
+}
+
+/**
+ * Worker node tasks queue options.
+ */
+export interface TasksQueueOptions {
+ /**
+ * Maximum tasks queue size per worker node flagging it as back pressured.
+ *
+ * @defaultValue (pool maximum size)^2
+ */
+ readonly size?: number
+ /**
+ * Maximum number of tasks that can be executed concurrently on a worker node.
+ *
+ * @defaultValue 1
+ */
+ readonly concurrency?: number
+ /**
+ * Whether to enable task stealing.
+ *
+ * @defaultValue true
+ */
+ readonly taskStealing?: boolean
+ /**
+ * Whether to enable tasks stealing on back pressure.
+ *
+ * @defaultValue true
+ */
+ readonly tasksStealingOnBackPressure?: boolean
+}
+
+/**
+ * Options for a poolifier pool.
+ *
+ * @typeParam Worker - Type of worker.
+ */
+export interface PoolOptions<Worker extends IWorker> {
+ /**
+ * A function that will listen for online event on each worker.
+ */
+ onlineHandler?: OnlineHandler<Worker>
+ /**
+ * A function that will listen for message event on each worker.
+ */
+ messageHandler?: MessageHandler<Worker>
+ /**
+ * A function that will listen for error event on each worker.
+ */
+ errorHandler?: ErrorHandler<Worker>
+ /**
+ * A function that will listen for exit event on each worker.
+ */
+ exitHandler?: ExitHandler<Worker>
+ /**
+ * Whether to start the minimum number of workers at pool initialization.
+ *
+ * @defaultValue false
+ */
+ startWorkers?: boolean
+ /**
+ * The worker choice strategy to use in this pool.
+ *
+ * @defaultValue WorkerChoiceStrategies.ROUND_ROBIN
+ */
+ workerChoiceStrategy?: WorkerChoiceStrategy
+ /**
+ * The worker choice strategy options.
+ */
+ workerChoiceStrategyOptions?: WorkerChoiceStrategyOptions
+ /**
+ * Restart worker on error.
+ */
+ restartWorkerOnError?: boolean
+ /**
+ * Pool events emission.
+ *
+ * @defaultValue true
+ */
+ enableEvents?: boolean
+ /**
+ * Pool worker node tasks queue.
+ *
+ * @defaultValue false
+ */
+ enableTasksQueue?: boolean
+ /**
+ * Pool worker node tasks queue options.
+ */
+ tasksQueueOptions?: TasksQueueOptions
+}
+