/**
 * V2 Reconciler Type Definitions
 *
 * The Reconciler is the "CPU" of Crewly V3 — it periodically recomputes
 * system truth from durable state, not trusting event delivery.
 * These types define its outputs and configuration.
 *
 * @module types/v2/reconcile.types
 */
/** All valid ReconcileType values. */
export const RECONCILE_TYPES = [
    'full',
    'targeted_request',
    'targeted_mission',
    'fast',
];
/**
 * Default Reconciler configuration values.
 * Performance budget: single reconcile < 3s (CEO requirement).
 */
export const DEFAULT_RECONCILER_CONFIG = {
    fastLoopIntervalMs: 10_000, // 10 seconds
    fullLoopIntervalMs: 60_000, // 60 seconds
    maxReconcileDurationMs: 3_000, // 3 seconds performance budget
    workItemTimeoutMs: 600_000, // 10 minutes
    maxHistorySize: 100,
    eventTriggeredEnabled: true,
};
// ---------------------------------------------------------------------------
// Type Guards
// ---------------------------------------------------------------------------
/**
 * Checks whether a string is a valid ReconcileType.
 *
 * @param value - The string to check
 * @returns True if value is a valid ReconcileType
 */
export function isValidReconcileType(value) {
    return RECONCILE_TYPES.includes(value);
}
/**
 * Validates that an unknown value is structurally a valid ReconcileResult.
 *
 * @param value - Unknown value to validate
 * @returns True if value conforms to the ReconcileResult interface
 */
export function isReconcileResult(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.requestsUpdated === 'number' &&
        typeof obj.workItemsTimedOut === 'number' &&
        typeof obj.workItemsRequeued === 'number' &&
        typeof obj.claimsRevoked === 'number' &&
        typeof obj.triggersRebuilt === 'number' &&
        typeof obj.staleItemsCleaned === 'number' &&
        typeof obj.reconciledAt === 'string' &&
        typeof obj.durationMs === 'number' &&
        typeof obj.type === 'string' &&
        isValidReconcileType(obj.type) &&
        typeof obj.agentsWoken === 'number' &&
        Array.isArray(obj.corrections) &&
        Array.isArray(obj.wakeActions) &&
        Array.isArray(obj.errors));
}
/**
 * Validates that an unknown value is a valid ReconcilerConfig.
 *
 * @param value - Unknown value to validate
 * @returns True if value conforms to ReconcilerConfig
 */
export function isValidReconcilerConfig(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.fastLoopIntervalMs === 'number' && obj.fastLoopIntervalMs > 0 &&
        typeof obj.fullLoopIntervalMs === 'number' && obj.fullLoopIntervalMs > 0 &&
        typeof obj.maxReconcileDurationMs === 'number' && obj.maxReconcileDurationMs > 0 &&
        typeof obj.workItemTimeoutMs === 'number' && obj.workItemTimeoutMs > 0 &&
        typeof obj.maxHistorySize === 'number' && obj.maxHistorySize > 0 &&
        typeof obj.eventTriggeredEnabled === 'boolean');
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
/**
 * Creates an empty ReconcileResult for a new reconciliation pass.
 *
 * @param type - The type of reconciliation being performed
 * @returns A ReconcileResult with all counters at zero
 */
export function createEmptyReconcileResult(type) {
    return {
        requestsUpdated: 0,
        workItemsTimedOut: 0,
        workItemsRequeued: 0,
        claimsRevoked: 0,
        triggersRebuilt: 0,
        staleItemsCleaned: 0,
        agentsWoken: 0,
        reconciledAt: new Date().toISOString(),
        durationMs: 0,
        type,
        corrections: [],
        wakeActions: [],
        errors: [],
    };
}
/**
 * Creates a ReconcileCorrection entry.
 *
 * @param params - Correction details
 * @returns A fully populated ReconcileCorrection
 */
export function createCorrection(params) {
    return {
        ...params,
        correctedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=reconcile.types.js.map