/**
 * Thread Status Types Module
 *
 * Type definitions for the Thread Status Queue system that tracks
 * the lifecycle of every inbound message thread across platforms.
 * On orchestrator restart, non-terminal threads are recovered and
 * re-enqueued for processing.
 *
 * @module types/thread-status
 */
/**
 * All valid thread status values as a tuple for runtime validation.
 */
export const THREAD_STATUS_VALUES = [
    'enqueued',
    'delivered',
    'replied_completed',
    'replied_waiting_actions',
    'replied_to_follow_up',
    'expired',
    'error',
];
/**
 * Terminal statuses that require no further orchestrator action.
 * Used by getPendingThreads() to filter out completed threads.
 *
 * Note: replied_to_follow_up is NOT terminal — it is waiting for user reply,
 * and on restart the follow-up tracking (scheduled check + event subscription)
 * must be re-established.
 */
export const TERMINAL_STATUSES = [
    'replied_completed',
    'expired',
];
// =============================================================================
// Persistence
// =============================================================================
/**
 * Version number for the persisted thread status queue format.
 * Increment when making breaking changes to the storage schema.
 */
export const PERSISTED_THREAD_STATUS_VERSION = 1;
// =============================================================================
// Type Guards
// =============================================================================
/**
 * Checks whether a value is a valid ThreadStatus string.
 *
 * @param value - Value to check
 * @returns True if value is a valid ThreadStatus
 */
export function isThreadStatus(value) {
    return typeof value === 'string' && THREAD_STATUS_VALUES.includes(value);
}
/**
 * Checks whether a given ThreadStatus is terminal (no further action needed).
 *
 * @param status - The status to check
 * @returns True if the status is terminal
 */
export function isTerminalStatus(status) {
    return TERMINAL_STATUSES.includes(status);
}
/**
 * Checks whether a value is a valid ThreadStatusEntry.
 * Validates required fields and their types.
 *
 * @param value - Value to check
 * @returns True if value conforms to ThreadStatusEntry
 */
export function isThreadStatusEntry(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.id === 'string' &&
        typeof obj.source === 'string' &&
        typeof obj.threadKey === 'string' &&
        typeof obj.conversationId === 'string' &&
        isThreadStatus(obj.status) &&
        typeof obj.receivedAt === 'string' &&
        typeof obj.updatedAt === 'string' &&
        typeof obj.messagePreview === 'string' &&
        typeof obj.retryCount === 'number');
}
/**
 * Checks whether a value is a valid PersistedThreadStatusState.
 *
 * @param value - Value to check
 * @returns True if value conforms to PersistedThreadStatusState
 */
export function isPersistedThreadStatusState(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.version === 'number' &&
        Array.isArray(obj.entries) &&
        typeof obj.lastCleanupAt === 'string');
}
/**
 * Checks whether a value is a valid ReplyStatus.
 *
 * @param value - Value to check
 * @returns True if value is a valid reply status
 */
export function isReplyStatus(value) {
    return value === 'replied_completed' || value === 'replied_waiting_actions' || value === 'replied_to_follow_up';
}
//# sourceMappingURL=thread-status.types.js.map