/**
 * Type definitions for the Unified Scheduler Service.
 *
 * The Unified Scheduler consolidates cron, interval, and idle-based
 * scheduling into a single interface with persistent storage and
 * agent auto-start capabilities.
 *
 * @module services/workflow/unified-scheduler.types
 */
// =============================================================================
// Constants
// =============================================================================
/** Default values for the unified scheduler. */
export const UNIFIED_SCHEDULER_CONSTANTS = {
    /** Evaluation loop interval (60 seconds — matches cron granularity) */
    EVAL_INTERVAL_MS: 60_000,
    /** Storage file path (relative to ~/.crewly/) */
    STORAGE_FILE: 'unified-schedules.json',
    /** Default max consecutive triggers before auto-pause */
    DEFAULT_MAX_CONSECUTIVE: 10,
    /** Storage schema version */
    SCHEMA_VERSION: '1.0.0',
    /** Default idle timeout if not specified (30 minutes) */
    DEFAULT_IDLE_TIMEOUT_MINUTES: 30,
};
// =============================================================================
// Validation
// =============================================================================
/** Valid schedule types for request validation. */
export const VALID_SCHEDULE_TYPES = new Set(['cron', 'interval', 'idle']);
/**
 * Validate a cron expression (basic 5-field format).
 *
 * Checks that the expression has exactly 5 space-separated fields
 * and each field contains only valid cron characters.
 *
 * @param expr - Cron expression to validate
 * @returns True if valid
 */
export function isValidCronExpression(expr) {
    const fields = expr.trim().split(/\s+/);
    if (fields.length !== 5)
        return false;
    const validChars = /^[\d,\-\*\/]+$/;
    return fields.every(f => validChars.test(f));
}
/**
 * Validate a CreateScheduleRequest.
 *
 * @param req - Request to validate
 * @returns Error message or null if valid
 */
export function validateCreateRequest(req) {
    if (!req.target || typeof req.target !== 'string')
        return 'target is required';
    if (!req.message || typeof req.message !== 'string')
        return 'message is required';
    if (!req.type || !VALID_SCHEDULE_TYPES.has(req.type)) {
        return `type must be one of: ${[...VALID_SCHEDULE_TYPES].join(', ')}`;
    }
    switch (req.type) {
        case 'cron':
            if (!req.cron)
                return 'cron expression is required when type=cron';
            if (!isValidCronExpression(req.cron))
                return `Invalid cron expression: ${req.cron}`;
            break;
        case 'interval':
            if (!req.intervalMinutes || req.intervalMinutes <= 0) {
                return 'intervalMinutes must be a positive number when type=interval';
            }
            break;
        case 'idle':
            if (!req.idleTimeoutMinutes || req.idleTimeoutMinutes <= 0) {
                return 'idleTimeoutMinutes must be a positive number when type=idle';
            }
            break;
    }
    return null;
}
//# sourceMappingURL=unified-scheduler.types.js.map