import { default as joi } from 'joi';
import { KyooQueue } from '../queue';
import { KyooAdapterToQueueBus } from '../utils/adapter_to_queue_bus';
import type { Serializable } from '@nhtio/serialization/types';
import type { ConnectionStatus, KyooConfigurationOptions } from '.';
import type { KyooConnectionToAdapterBus } from '../utils/connection_to_adapter_bus';
import type { KyooJob, KyooJobToEnqueue, KyooWorkable } from '../job';
import type { DatabaseOptions as PostgreSQLDatabaseOptions, QueueOptions as PostgreSQLQueueOptions, SchedulingOptions as PostgreSQLSchedulingOptions, MaintenanceOptions as PostgreSQLMaintenanceOptions, ExpirationOptions as PostgreSQLExpirationOptions, RetentionOptions as PostgreSQLRetentionOptions, RetryOptions as PostgreSQLRetryOptions, JobPollingOptions as PostgreSQLJobPollingOptions } from 'pg-boss';
export type { DatabaseOptions as PostgreSQLDatabaseOptions, QueueOptions as PostgreSQLQueueOptions, SchedulingOptions as PostgreSQLSchedulingOptions, MaintenanceOptions as PostgreSQLMaintenanceOptions, ExpirationOptions as PostgreSQLExpirationOptions, RetentionOptions as PostgreSQLRetentionOptions, RetryOptions as PostgreSQLRetryOptions, JobPollingOptions as PostgreSQLJobPollingOptions, } from 'pg-boss';
/**
 * A URL using the "postgres" protocol.
 */
export type PostgreSQLConnectionString = `postgres://${string}`;
/**
 * A configuration object for connecting to a PostgreSQL database.
 * @interface
 * @prop database - The name of the database to connect to.
 * @prop user - The username to connect to the database.
 * @prop password - The password for the user.
 * @prop host - The host of the PostgreSQL server.
 * @prop port - The port of the PostgreSQL server.
 * @prop ssl - Optional SSL configuration for the connection.
 */
export type PostgreSQLConnectionObject = Omit<PostgreSQLDatabaseOptions, 'connectionString' | 'db' | 'max' | 'application_name' | 'schema'>;
/**
 * Configuration for the PGBoss adapter.
 * @see {@link https://timgit.github.io/pg-boss/#/./api/constructor | PGBoss constructor documentation}
 */
export interface PGBossAdapterConfiguration {
    /**
     * The connection to the PostgreSQL database.
     * It can be either a connection string or an object with connection options.
     */
    connection: PostgreSQLConnectionObject | PostgreSQLConnectionString;
    /**
     * Maximum number of connections that will be shared by all operations in this instance.
     * If not specified, it defaults to 10.
     */
    maxConnections?: number;
    /**
     * The name of the application using PGBoss.
     * Defaults to `'pg-boss'`.
     */
    applicationName?: string;
    /**
     * The schema to use for the PGBoss tables.
     * If not specified, it defaults to `'pgboss'`.
     */
    schema?: string;
    /**
     * Connection-level options for queues
     * @prop monitorStateIntervalSeconds - Specifies how long in seconds completed jobs get archived. Note: a warning will be emitted if set to lower than 60s and cron processing will be disabled.
     * Defaults to 12 hours
     * @prop monitorStateIntervalMinutes Specifies how long in seconds failed jobs get archived. Note: a warning will be emitted if set to lower than 60s and cron processing will be disabled.
     * Defaults to the same value as `monitorStateIntervalSeconds`
     */
    queueOptions?: PostgreSQLQueueOptions;
    /**
     * Scheduling options for the PGBoss instance.
     * @prop schedule – Enable or disable the internal scheduler (delayed jobs & cron). Defaults to `true`.
     * @prop clockMonitorIntervalSeconds – How often, in seconds, to check and correct for clock skew between your application and the Postgres server.
     * @prop clockMonitorIntervalMinutes – Alternate interval, in minutes, for clock skew checks; ignored if `clockMonitorIntervalSeconds` is also set.
     * @prop cronMonitorIntervalSeconds – How often, in seconds, to perform a health check on the cron scheduler and re-enqueue any missed ticks.
     * @prop cronWorkerIntervalSeconds – How often, in seconds, the cron worker polls for and dispatches scheduled jobs.
     */
    schedulingOptions?: PostgreSQLSchedulingOptions;
    /**
     * Maintenance options for the PGBoss instance.
     * @prop supervise – Enable or disable the internal maintenance supervisor (archiving & cleanup). Defaults to `true`.
     * @prop migrate – Enable or disable automatic schema migrations at startup. Defaults to `true`.
     * @prop deleteAfterSeconds – Time in seconds after which archived jobs are permanently deleted.
     * @prop deleteAfterMinutes – Time in minutes after which archived jobs are permanently deleted; ignored if `deleteAfterSeconds` is also set.
     * @prop deleteAfterHours – Time in hours after which archived jobs are permanently deleted; ignored if `deleteAfterSeconds` or `deleteAfterMinutes` is also set.
     * @prop deleteAfterDays – Time in days after which archived jobs are permanently deleted; ignored if any smaller `deleteAfter*` option is set.
     * @prop maintenanceIntervalSeconds – How often, in seconds, to run maintenance tasks (archiving, deletion, etc.).
     * @prop maintenanceIntervalMinutes – How often, in minutes, to run maintenance tasks; ignored if `maintenanceIntervalSeconds` is also set.
     * @prop archiveCompletedAfterSeconds – Time in seconds after a job completes before it is moved to the archive table.
     * @prop archiveFailedAfterSeconds – Time in seconds after a job fails before it is moved to the archive table.
     */
    maintenanceOptions?: PostgreSQLMaintenanceOptions;
    /**
     * Expiration options for active jobs in PGBoss.
     * @prop expireInSeconds – The number of seconds a job can remain in the active state before it is considered expired and failed. :contentReference[oaicite:0]{index=0}
     * @prop expireInMinutes – The number of minutes a job can remain in the active state before it is considered expired and failed. :contentReference[oaicite:1]{index=1}
     * @prop expireInHours – The number of hours a job can remain in the active state before it is considered expired and failed. :contentReference[oaicite:2]{index=2}
     */
    expirationOptions?: PostgreSQLExpirationOptions;
    /**
     * Retention options for PGBoss jobs.
     * @prop retentionSeconds – How long, in seconds, to keep a job in the created or retry state before moving it to the archive.
     * @prop retentionMinutes – How long, in minutes, to keep a job in the created or retry state before moving it to the archive; ignored if `retentionSeconds` is also set.
     * @prop retentionHours – How long, in hours, to keep a job in the created or retry state before moving it to the archive; ignored if `retentionSeconds` or `retentionMinutes` is also set.
     * @prop retentionDays – How long, in days, to keep a job in the created or retry state before moving it to the archive; ignored if any smaller `retention*` option is set.
     */
    retentionOptions?: PostgreSQLRetentionOptions;
    /**
     * Retry options for PGBoss jobs.
     * @prop retryLimit – Maximum number of times to retry a failed job before marking it as permanently failed; uses the instance-level default if omitted.
     * @prop retryDelay – Delay, in milliseconds, between retry attempts; ignored when `retryBackoff` is enabled.
     * @prop retryBackoff – Enable exponential backoff for retries (delay multiplied by the attempt number). Defaults to `false`.
     */
    retryOptions?: PostgreSQLRetryOptions;
    /**
     * Job polling options for the PGBoss instance.
     * @prop pollingIntervalSeconds – Interval, in seconds, between polls for new jobs on active queues; uses the instance‐level default when omitted.
     */
    jobPollingOptions?: PostgreSQLJobPollingOptions;
    /**
     * Whether to enforce the sequence of job enqueueing.
     * If set to `true`, jobs will be enqueued in the order they are provided.
     * Defaults to `false`.
     */
    enforceEnqueueSequence?: boolean;
}
/**
 * Comprehensive schema for PGBossAdapterConfiguration.
 */
export declare const pgBossAdapterConfigurationSchema: joi.ObjectSchema<PGBossAdapterConfiguration>;
/** @private */
export declare class PGBossAdapter {
    #private;
    /**
     * @private
     */
    constructor(configuration: PGBossAdapterConfiguration, bus: KyooConnectionToAdapterBus, options: KyooConfigurationOptions);
    get connectionStatus(): ConnectionStatus;
    connect(signal?: AbortSignal): Promise<boolean>;
    disconnect(terminate?: boolean): Promise<void>;
    get queues(): {
        get: (name: string, bus: KyooAdapterToQueueBus) => KyooQueue<"pgboss">;
        readonly count: number;
        terminate: (name?: string) => Promise<void[] | undefined>;
        destroy: (name: string) => Promise<void>;
    };
    get jobs(): {
        enqueue: (queue: string, ...jobs: KyooJobToEnqueue[]) => Promise<boolean | any[]>;
        purge: (queue: string) => Promise<void>;
        next: <T = Serializable>(queue: string, noAck?: boolean, rejectable?: boolean, onDispositioned?: (disposition: "ack" | "nack") => void) => Promise<KyooWorkable<T> | undefined>;
        enqueued: (queue: string) => Promise<number>;
        fetch: <T = Serializable>(queue: string, count: number) => Promise<Array<KyooJob<T>>>;
    };
}
