import type { ID, Timestamp } from '../common/types.js';
/**
 * Feature flag definition
 */
export interface FeatureFlag {
    /** Unique flag identifier */
    id: ID;
    /** Flag name */
    name: string;
    /** Flag description */
    description?: string;
    /** Whether flag is enabled */
    enabled: boolean;
    /** Percentage of traffic to enable for (0-100) */
    percentage?: number;
    /** Specific entity IDs to include */
    includeEntities?: ID[];
    /** Specific entity IDs to exclude */
    excludeEntities?: ID[];
    /** Specific tenant IDs to include */
    includeTenants?: ID[];
    /** Specific tenant IDs to exclude */
    excludeTenants?: ID[];
    /** Expiration timestamp */
    expiresAt?: Timestamp;
    /** Metadata */
    metadata?: Record<string, unknown>;
    /** Created timestamp */
    createdAt: Timestamp;
    /** Updated timestamp */
    updatedAt: Timestamp;
}
/**
 * Enforcement mode
 */
export type EnforcementMode = 'strict' | 'permissive' | 'audit-only' | 'shadow' | 'disabled';
/**
 * A/B test variant
 */
export interface ABTestVariant {
    /** Variant identifier */
    id: ID;
    /** Variant name */
    name: string;
    /** Traffic allocation percentage (0-100) */
    allocation: number;
    /** Configuration overrides for this variant */
    config: Record<string, unknown>;
    /** Metrics to track */
    metrics?: string[];
}
/**
 * A/B test definition
 */
export interface ABTest {
    /** Unique test identifier */
    id: ID;
    /** Test name */
    name: string;
    /** Test description */
    description?: string;
    /** Whether test is active */
    active: boolean;
    /** Test variants */
    variants: ABTestVariant[];
    /** Control variant ID */
    controlVariantId: ID;
    /** Traffic percentage for test (0-100) */
    trafficPercentage: number;
    /** Assignment strategy */
    assignmentStrategy: 'random' | 'entity-hash' | 'tenant-hash';
    /** Start timestamp */
    startedAt?: Timestamp;
    /** End timestamp */
    endedAt?: Timestamp;
    /** Target sample size */
    targetSampleSize?: number;
    /** Current sample counts per variant */
    sampleCounts: Map<ID, number>;
    /** Metadata */
    metadata?: Record<string, unknown>;
    /** Created timestamp */
    createdAt: Timestamp;
    /** Updated timestamp */
    updatedAt: Timestamp;
}
/**
 * A/B test assignment result
 */
export interface ABTestAssignment {
    /** Test ID */
    testId: ID;
    /** Test name */
    testName: string;
    /** Assigned variant */
    variant: ABTestVariant;
    /** Assignment key (entity/tenant ID) */
    assignmentKey: string;
    /** Assignment timestamp */
    assignedAt: Timestamp;
}
/**
 * Policy configuration reload event
 */
export interface ReloadEvent {
    /** Event ID */
    id: ID;
    /** Event type */
    type: 'policy' | 'feature-flag' | 'ab-test' | 'config';
    /** Action taken */
    action: 'add' | 'update' | 'remove' | 'reload';
    /** Resource ID affected */
    resourceId?: ID;
    /** Old value (for updates) */
    oldValue?: unknown;
    /** New value */
    newValue?: unknown;
    /** Event timestamp */
    timestamp: Timestamp;
    /** Source of the change */
    source: string;
    /** Success status */
    success: boolean;
    /** Error if failed */
    error?: string;
}
/**
 * Configuration value with metadata
 */
export interface ConfigValue<T = unknown> {
    /** The configuration value */
    value: T;
    /** Default value */
    defaultValue: T;
    /** Value description */
    description?: string;
    /** Whether value can be changed at runtime */
    mutable: boolean;
    /** Validation function */
    validate?: (value: T) => boolean;
    /** Last updated timestamp */
    updatedAt: Timestamp;
    /** Update source */
    updatedBy?: string;
}
/**
 * Runtime configuration options
 */
export interface RuntimeConfigOptions {
    /** Enable OpenTelemetry tracing */
    enableTracing?: boolean;
    /** Default enforcement mode */
    defaultEnforcementMode?: EnforcementMode;
    /** Reload check interval in ms */
    reloadCheckIntervalMs?: number;
    /** Maximum reload events to keep */
    maxReloadEvents?: number;
    /** Configuration source (for external config) */
    configSource?: ConfigSource;
    /** Enable A/B testing */
    enableABTesting?: boolean;
}
/**
 * Configuration source interface for external config systems
 */
export interface ConfigSource {
    /** Load all configuration */
    loadAll(): Promise<Record<string, unknown>>;
    /** Watch for changes */
    watch(callback: (key: string, value: unknown) => void): () => void;
    /** Get specific key */
    get(key: string): Promise<unknown>;
    /** Set specific key */
    set(key: string, value: unknown): Promise<void>;
}
/**
 * In-memory configuration source
 */
export declare class InMemoryConfigSource implements ConfigSource {
    private data;
    private watchers;
    loadAll(): Promise<Record<string, unknown>>;
    watch(callback: (key: string, value: unknown) => void): () => void;
    get(key: string): Promise<unknown>;
    set(key: string, value: unknown): Promise<void>;
    delete(key: string): boolean;
    clear(): void;
}
/**
 * RuntimeConfig class for dynamic configuration management
 */
export declare class RuntimeConfig {
    private options;
    private featureFlags;
    private abTests;
    private configValues;
    private reloadEvents;
    private configSource;
    private enforcementMode;
    private changeListeners;
    private variantAssignments;
    constructor(options?: RuntimeConfigOptions);
    /**
     * Get current enforcement mode
     */
    getEnforcementMode(): EnforcementMode;
    /**
     * Set enforcement mode
     */
    setEnforcementMode(mode: EnforcementMode, source?: string): void;
    /**
     * Check if enforcement is active
     */
    isEnforcementActive(): boolean;
    /**
     * Check if should deny on violation
     */
    shouldDenyOnViolation(): boolean;
    /**
     * Check if should audit
     */
    shouldAudit(): boolean;
    /**
     * Add a feature flag
     */
    addFeatureFlag(flag: FeatureFlag): void;
    /**
     * Update a feature flag
     */
    updateFeatureFlag(flagId: ID, updates: Partial<FeatureFlag>, source?: string): boolean;
    /**
     * Remove a feature flag
     */
    removeFeatureFlag(flagId: ID, source?: string): boolean;
    /**
     * Check if a feature flag is enabled for a context
     */
    isFeatureEnabled(flagId: ID, context?: {
        entityId?: ID;
        tenantId?: ID;
    }): boolean;
    /**
     * Get all feature flags
     */
    getFeatureFlags(): FeatureFlag[];
    /**
     * Get a feature flag by ID
     */
    getFeatureFlag(flagId: ID): FeatureFlag | undefined;
    /**
     * Add an A/B test
     */
    addABTest(test: ABTest): void;
    /**
     * Start an A/B test
     */
    startABTest(testId: ID): boolean;
    /**
     * Stop an A/B test
     */
    stopABTest(testId: ID): boolean;
    /**
     * Get A/B test variant assignment
     */
    getABTestAssignment(testId: ID, context: {
        entityId: ID;
        tenantId?: ID;
    }): ABTestAssignment | null;
    /**
     * Assign variant based on test strategy
     */
    private assignVariant;
    /**
     * Get all A/B tests
     */
    getABTests(): ABTest[];
    /**
     * Get active A/B tests
     */
    getActiveABTests(): ABTest[];
    /**
     * Get A/B test by ID
     */
    getABTest(testId: ID): ABTest | undefined;
    /**
     * Get A/B test results
     */
    getABTestResults(testId: ID): {
        variant: ABTestVariant;
        sampleCount: number;
    }[] | null;
    /**
     * Set a configuration value
     */
    setConfig<T>(key: string, value: T, options?: {
        defaultValue?: T;
        description?: string;
        mutable?: boolean;
        validate?: (value: T) => boolean;
        source?: string;
    }): boolean;
    /**
     * Get a configuration value
     */
    getConfig<T>(key: string, defaultValue?: T): T | undefined;
    /**
     * Get config with metadata
     */
    getConfigWithMetadata<T>(key: string): ConfigValue<T> | undefined;
    /**
     * Delete a configuration value
     */
    deleteConfig(key: string, source?: string): boolean;
    /**
     * Get all configuration keys
     */
    getConfigKeys(): string[];
    /**
     * Get all configuration values
     */
    getAllConfig(): Record<string, unknown>;
    /**
     * Reload configuration from source
     */
    reload(source?: string): Promise<boolean>;
    /**
     * Sync configuration to source
     */
    sync(source?: string): Promise<boolean>;
    /**
     * Register a change listener
     */
    onConfigChange(listener: (event: ReloadEvent) => void): () => void;
    /**
     * Record a reload event and notify listeners
     */
    private recordEvent;
    /**
     * Get reload events
     */
    getReloadEvents(limit?: number): ReloadEvent[];
    /**
     * Simple string hash function
     */
    private hashString;
    /**
     * Clear all configuration
     */
    clear(): void;
    /**
     * Get configuration statistics
     */
    getStats(): {
        enforcementMode: EnforcementMode;
        featureFlags: number;
        enabledFlags: number;
        abTests: number;
        activeTests: number;
        configValues: number;
        reloadEvents: number;
    };
}
/**
 * Create a new runtime config instance
 */
export declare function createRuntimeConfig(options?: RuntimeConfigOptions): RuntimeConfig;
/**
 * Create a feature flag with defaults
 */
export declare function createFeatureFlag(partial: Partial<FeatureFlag> & Pick<FeatureFlag, 'id' | 'name'>): FeatureFlag;
/**
 * Create an A/B test with defaults
 */
export declare function createABTest(partial: Partial<ABTest> & Pick<ABTest, 'id' | 'name' | 'variants' | 'controlVariantId'>): ABTest;
/**
 * Create an A/B test variant
 */
export declare function createABTestVariant(partial: Partial<ABTestVariant> & Pick<ABTestVariant, 'id' | 'name' | 'allocation'>): ABTestVariant;
//# sourceMappingURL=runtime-config.d.ts.map