/**
 * Cron Scheduler
 *
 * Gateway-integrated job scheduler supporting:
 * - One-shot (at) - ISO 8601 timestamp
 * - Fixed intervals (every) - millisecond-based
 * - Cron expressions (cron) - 5-field syntax + timezone
 *
 * Inspired by OpenClaw's cron scheduling system.
 */
import { EventEmitter } from 'events';
export type ScheduleType = 'at' | 'every' | 'cron';
export type JobStatus = 'active' | 'paused' | 'completed' | 'error';
export interface CronJob {
    /** Unique job ID */
    id: string;
    /** Job name/label */
    name: string;
    /** Job description */
    description?: string;
    /** Schedule type */
    type: ScheduleType;
    /** Schedule specification */
    schedule: {
        /** ISO 8601 timestamp for 'at' type */
        at?: string;
        /** Interval in milliseconds for 'every' type */
        every?: number;
        /** Cron expression for 'cron' type (5-field) */
        cron?: string;
        /** IANA timezone (default: local) */
        timezone?: string;
    };
    /** Task to execute */
    task: {
        /** Task type */
        type: 'message' | 'tool' | 'agent';
        /** Message content (for message type) */
        message?: string;
        /** Tool name and arguments (for tool type) */
        tool?: {
            name: string;
            arguments: Record<string, unknown>;
        };
        /** Agent ID (for agent type) */
        agentId?: string;
        /** Model override */
        model?: string;
    };
    /** Delivery options */
    delivery?: {
        /** Channel to deliver to */
        channel?: string;
        /** Session key */
        sessionKey?: string;
        /** Webhook URL */
        webhookUrl?: string;
    };
    /** Job status */
    status: JobStatus;
    /** Creation timestamp */
    createdAt: Date;
    /** Last run timestamp */
    lastRunAt?: Date;
    /** Next run timestamp */
    nextRunAt?: Date;
    /** Run count */
    runCount: number;
    /** Error count */
    errorCount: number;
    /** Last error */
    lastError?: string;
    /** Max runs (undefined = unlimited) */
    maxRuns?: number;
    /** Enabled flag */
    enabled: boolean;
}
export interface JobRun {
    id: string;
    jobId: string;
    startedAt: Date;
    completedAt?: Date;
    status: 'running' | 'success' | 'error';
    result?: unknown;
    error?: string;
    duration?: number;
}
export interface CronSchedulerConfig {
    /** Jobs persist path */
    persistPath: string;
    /** Run history path */
    historyPath: string;
    /** Max history entries per job */
    maxHistoryPerJob: number;
    /** Tick interval in ms */
    tickIntervalMs: number;
    /** Default timezone */
    defaultTimezone: string;
}
export declare const DEFAULT_CRON_SCHEDULER_CONFIG: CronSchedulerConfig;
export interface CronSchedulerEvents {
    'job:created': (job: CronJob) => void;
    'job:updated': (job: CronJob) => void;
    'job:deleted': (jobId: string) => void;
    'job:run:start': (run: JobRun) => void;
    'job:run:complete': (run: JobRun) => void;
    'job:run:error': (run: JobRun, error: Error) => void;
    'error': (error: Error) => void;
}
export declare class CronScheduler extends EventEmitter {
    private config;
    private jobs;
    private timers;
    private tickTimer;
    private running;
    private taskExecutor?;
    constructor(config?: Partial<CronSchedulerConfig>);
    /**
     * Set the task executor (for CronAgentBridge integration)
     */
    setTaskExecutor(executor: (job: CronJob) => Promise<unknown>): void;
    start(taskExecutor?: (job: CronJob) => Promise<unknown>): Promise<void>;
    stop(): Promise<void>;
    /**
     * Add a new job
     */
    addJob(params: {
        name: string;
        description?: string;
        type: ScheduleType;
        schedule: CronJob['schedule'];
        task: CronJob['task'];
        delivery?: CronJob['delivery'];
        maxRuns?: number;
        enabled?: boolean;
    }): Promise<CronJob>;
    /**
     * Update a job
     */
    updateJob(jobId: string, updates: Partial<Pick<CronJob, 'name' | 'description' | 'schedule' | 'task' | 'delivery' | 'maxRuns' | 'enabled'>>): Promise<CronJob | null>;
    /**
     * Remove a job
     */
    removeJob(jobId: string): Promise<boolean>;
    /**
     * Get a job by ID
     */
    getJob(jobId: string): CronJob | undefined;
    /**
     * List all jobs
     */
    listJobs(params?: {
        status?: JobStatus;
        type?: ScheduleType;
        enabled?: boolean;
    }): CronJob[];
    /**
     * Pause a job
     */
    pauseJob(jobId: string): Promise<boolean>;
    /**
     * Resume a job
     */
    resumeJob(jobId: string): Promise<boolean>;
    /**
     * Run a job immediately
     */
    runJobNow(jobId: string): Promise<JobRun | null>;
    private scheduleJob;
    private cancelJobTimer;
    private calculateNextRun;
    private executeJob;
    private tick;
    private loadJobs;
    private persistJobs;
    private saveRunHistory;
    private pruneRunHistory;
    /**
     * Get run history for a job
     */
    getRunHistory(jobId: string, limit?: number): Promise<JobRun[]>;
    getStats(): {
        totalJobs: number;
        activeJobs: number;
        pausedJobs: number;
        completedJobs: number;
        byType: Record<ScheduleType, number>;
    };
}
export declare function getCronScheduler(config?: Partial<CronSchedulerConfig>): CronScheduler;
export declare function resetCronScheduler(): Promise<void>;
export default CronScheduler;
