import { DateTime } from 'luxon';
import { default as joi } from 'joi';
import type { ValidationError } from 'joi';
import type { Serializable } from '@nhtio/serialization/types';
export type { ValidationError };
/**
 * Defines the possible job priority values.
 * The priority is a number between 1 and 255.
 * The higher the number, the higher the priority.
 */
export type KyooJobPriority = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255;
/**
 * A job is a unit of work that can be processed by a worker.
 * It contains a payload and optional metadata.
 */
export interface KyooJob<T = Serializable> {
    id: string;
    payload: T;
    persistent: boolean;
    expiration: DateTime | null;
    headers: Record<string, Serializable>;
    priority: KyooJobPriority;
    maxAttempts: number;
}
/**
 * Describes the shape of a job which should be enqueued.
 */
export interface KyooJobToEnqueue<T = any> {
    id?: string;
    payload: T;
    persistent?: boolean;
    expiration?: DateTime;
    headers?: Record<string, Serializable>;
    priority?: KyooJobPriority;
    maxAttempts?: number;
}
export interface EnqueueableKyooJob extends Record<string, Serializable> {
    id: string;
    payload: Serializable;
    persistent: boolean;
    expiration: Date | null;
    headers: Record<string, Serializable>;
    priority: KyooJobPriority;
    attempts: number;
    maxAttempts: number;
}
export declare const kyooJobSchema: joi.ObjectSchema<KyooJob<Serializable>>;
/**
 * A schema for validating job objects for the SQS broker.
 * It ensures that the job has a payload and optional metadata.
 */
export declare const kyooSQSJobSchema: joi.ObjectSchema<KyooJob<Serializable>>;
/**
 * A schema for validating an array of job objects.
 * It ensures that each job in the array is valid.
 */
export declare const kyooJobsSchema: joi.ArraySchema<any[]>;
/**
 * A schema for validating an array of job objects to be used with the SQS adapter.
 * It ensures that each job in the array is valid.
 */
export declare const kyooSQSJobsSchema: joi.ArraySchema<any[]>;
/**
 * Shape of the job acknowledgment function.
 */
export interface KyooJobAck {
    (): Promise<void>;
}
/**
 * Shape of the job negative acknowledgment function.
 * @param requeue Whether to re-enqueue the job, and if so whether to requeue it at the start (next job to process) or end (last job to process) of the queue.
 * If `true`, the job will be re-enqueued at the start (next job to process) of the queue.
 *
 * @remarks In amqp, to re-enqueue the job at the end of the queue, we simply nack() and re-add it to the end of the queue.
 * in bullmq, we use `lifo` to re-enqueue at the beginning of the queue.
 * in sqs, to re-enqueue the job at the end of the queue, we simply delete the message and re-add it to the end of the queue.
 *
 * Due to limitations with amqp, we cannot requeue a job at the beginning of the queue if we also need to honor the maxAttempts.
 * In this case, we will requeue the job at the end of the queue.
 */
export interface KyooJobNack {
    (requeue?: 'start' | 'end' | boolean): Promise<void>;
}
/**
 * A workable job is a job that can be processed by a worker.
 * It contains the job and methods for acknowledging or rejecting the job.
 */
export interface KyooWorkable<T = Serializable> {
    job: KyooJob<T>;
    ack: KyooJobAck;
    nack: KyooJobNack;
    attempts: number;
}
/**
 * Checks if a job is valid and can be enqueued.
 * @param job The job to check
 * @returns `true` if the job is valid, `false` otherwise
 */
export declare const canEnqueue: (job: unknown) => boolean;
/**
 * Validates and sanitizes a job object.
 * @param job The job to check
 * @throws KyooUnenqueueableError if the job is invalid
 * @returns The validated & sanitized job
 */
export declare const sanitizeJob: (job: unknown) => KyooJob;
export declare const enqueuableJob: (job: KyooJob) => EnqueueableKyooJob;
interface JobOptions {
    disableCompression?: boolean;
}
/**
 * Gzip a buffer and prepend the "gz:" prefix. Passthrough if disabled.
 */
export declare const compressPayload: (buf: Buffer, options?: JobOptions) => Promise<Buffer>;
/**
 * Strip "gz:" prefix and gunzip if present. Always auto-detects regardless of options.
 */
export declare const decompressPayload: (buf: Buffer) => Promise<Buffer>;
/**
 * Synchronous variant of compressPayload. Gzips a buffer and prepends the "gz:" prefix.
 */
export declare const compressPayloadSync: (buf: Buffer, options?: JobOptions) => Buffer;
/**
 * Synchronous variant of decompressPayload. Strips "gz:" prefix and gunzips if present.
 */
export declare const decompressPayloadSync: (buf: Buffer) => Buffer;
/**
 * Prepares the enqueuable job to be saved.
 * Serializes and compresses (if not disabled) the payload
 */
export declare const prepareEnqueuable: (enqueuable: EnqueueableKyooJob, options?: JobOptions) => Promise<Buffer>;
/**
 * Consumes the row job from the adapter.
 * Decompresses and deserializes the payload.
 */
export declare const consumeEnqueuable: (buffer: Buffer) => Promise<EnqueueableKyooJob>;
export declare const makeKyooWorkableFromEnqueuable: <T = Serializable>(enqueuable: EnqueueableKyooJob, onAck: KyooJobAck, onNack: KyooJobNack) => KyooWorkable<T>;
