import { KosModelRegistrationType } from '../../../core';
import { IKosDataModel, KosCreationContext } from '../../../core/core/kosModel';
import { IKosIdentifiable } from '../../../core/core/types';
import { PublicModelInterface } from '../../../core/types';
import { KosExpressionEvaluatorOptions } from './types';
export declare const MODEL_TYPE = "kos-expression-evaluator-model";
/**
 * Result of evaluating an expression, containing either a successful value or error details.
 *
 * @example
 * ```typescript
 * const result = evaluator.getExpressionValue('myExpression');
 * if (result?.error) {
 *   console.error(`Expression error: ${result.error}`);
 * } else {
 *   console.log(`Result: ${result?.value}`);
 * }
 * ```
 */
export interface ExpressionResult {
    /** The computed value of the expression, or undefined if evaluation failed */
    value: unknown;
    /** Error message if expression evaluation failed, undefined if successful */
    error?: string;
}
export interface NamedExpression {
    /** Unique name identifier for this expression */
    name: string;
    /** The expression string (JavaScript-like syntax) */
    expression: string;
    /** Getter that returns the cached result */
    get result(): ExpressionResult;
    /** Method to evaluate the expression with given context data */
    evaluate(contextData: Record<string, unknown>): ExpressionResult;
    /** Method to update the cached result */
    updateResult(result: ExpressionResult): void;
}
/**
 * KOS Expression Evaluator Model - Reactive expression evaluation with dynamic context and type-safe named expressions.
 *
 * This model provides a reactive expression evaluation system that automatically re-evaluates
 * expressions when their context data changes. Perfect for business rules, computed values,
 * and conditional logic that needs to stay synchronized with changing data.
 *
 * ## Key Features
 * - **Automatic reactivity** - Expressions re-evaluate when dependencies change thanks to KOS reactive patterns
 * - **Type safety** - Generic type parameter provides compile-time checking for expression names
 * - **Efficient updates** - Only affected expressions recalculate when their data dependencies change
 * - **Synchronous access** - Results available immediately via getters
 * - **Error handling** - Expressions with runtime errors are handled gracefully
 * - **KOS model integration** - Add any KOS model to context for fully reactive expressions
 *
 * @interface
 * @example Basic Usage
 * ```typescript
 * const evaluator = KosExpressionEvaluatorModel.instance('my-evaluator').build();
 *
 * evaluator.setContextData({ temperature: 72, humidity: 45 });
 * evaluator.addExpression('isComfortable', 'temperature >= 68 && temperature <= 78');
 *
 * console.log(evaluator.results.isComfortable?.value); // true
 * ```
 *
 * @group KOS Model
 * @category Expression Processing
 * @useDeclaredType
 */
export type KosExpressionEvaluatorModel<T extends string = string> = PublicModelInterface<KosExpressionEvaluatorModelImpl<T>>;
/**
 * @ignore
 * @internal
 */
export declare class KosExpressionEvaluatorModelImpl<T extends string = string> implements IKosDataModel, IKosIdentifiable {
    static Registration: KosModelRegistrationType<KosExpressionEvaluatorModel, KosExpressionEvaluatorOptions>;
    id: string;
    private logger;
    private parser;
    private _data;
    private _expressions;
    private _results;
    private _contextRevision;
    constructor(modelId: string, options: KosExpressionEvaluatorOptions, context: KosCreationContext);
    /**
     * Get the current context data that expressions are evaluated against.
     *
     * @returns The current context data as a record of key-value pairs
     */
    get data(): Record<string, unknown>;
    get contextRevision(): number;
    /**
     * Replace the entire context data with new values. All expressions will
     * automatically re-evaluate against the new context.
     *
     * @param newData - Complete new context data to replace existing data
     *
     * @example
     * ```typescript
     * evaluator.setContextData({ temperature: 75, humidity: 40 });
     * ```
     */
    setContextData(newData: Record<string, unknown>): void;
    /**
     * Update a single value in the context data. All expressions using this
     * value will automatically re-evaluate.
     *
     * @param key - The context data key to update
     * @param value - The new value to set
     *
     * @example
     * ```typescript
     * evaluator.updateContextValue('temperature', 85);
     * ```
     */
    updateContextValue(key: string, value: unknown): void;
    /**
     * Update a nested property in the context data using dot notation.
     * This method safely updates nested properties without replacing the entire object structure.
     *
     * @param path - Dot-separated path to the nested property (e.g., 'sensors.humidity', 'config.thresholds.temp')
     * @param value - The new value to set at the nested path
     *
     * @example
     * ```typescript
     * evaluator.updateNestedValue('sensors.humidity', 60);
     * ```
     */
    updateNestedValue(path: string, value: unknown): void;
    /**
     * Add a KOS model to the evaluation context. The model's observable properties
     * will be accessible via dotted notation and expressions will automatically
     * re-evaluate when the model's data changes.
     *
     * @param key - The context key to store the model under
     * @param model - Any KOS model instance (must be observable)
     *
     * @example
     * ```typescript
     * const sensorModel = SensorModel.instance('main-sensor').build();
     * evaluator.addModelToContext('sensor', sensorModel);
     * evaluator.addExpression('isCritical', 'sensor.temperature > 80');
     * ```
     */
    addModelToContext(key: string, model: unknown): void;
    /**
     * Add a named expression that will be automatically evaluated against context data.
     * The expression will re-evaluate whenever its dependencies in the context change.
     *
     * @param name - Unique identifier for this expression (type-safe when using generic)
     * @param expressionString - JavaScript-like expression string
     * @throws {Error} If the expression has invalid syntax
     *
     * @example
     * ```typescript
     * evaluator.addExpression('isHot', 'temperature > 80');
     * ```
     */
    addExpression(name: T, expressionString: string): void;
    removeExpression(name: T): boolean;
    getExpression(name: T): NamedExpression | undefined;
    getExpressionValue(name: T): ExpressionResult | undefined;
    /**
     * Get the cached result of an expression without triggering re-evaluation.
     * This is useful for dependency tracking in effects where you want to avoid
     * creating reactive chains through the expression evaluation.
     *
     * @param name - The expression name to get the cached result for
     * @returns The last cached result, or undefined if expression doesn't exist
     *
     * @example
     * ```typescript
     * const cached = evaluator.getCachedExpressionValue('myExpression');
     * ```
     */
    getCachedExpressionValue(name: T): ExpressionResult | undefined;
    get expressions(): NamedExpression[];
    get expressionNames(): T[];
    get results(): Record<T, ExpressionResult>;
    /**
     * Force re-evaluation of all expressions and update cached results.
     * This is called by the effect when context data changes.
     */
    private evaluateAllExpressions;
    /**
     * Evaluate a specific expression and update the cached result if it changed.
     */
    private evaluateExpression;
    /**
     * Internal method to update the results object when expression values change.
     * This is called by ReactiveExpression when its value changes.
     * ObservableData handles dynamic properties automatically with MobX atoms.
     */
    private updateResult;
    /**
     * Create an anonymous reactive expression and return its generated ID.
     * The expression becomes fully reactive and can be accessed via the returned ID.
     *
     * @param expressionString - JavaScript-like expression string
     * @returns Generated UUID that can be used to access the expression via `getExpressionValue(id)` or `results[id]`
     *
     * @example
     * ```typescript
     * const tempCheckId = evaluator.createExpression('temperature > 75');
     * const result = evaluator.getExpressionValue(tempCheckId);
     * ```
     */
    createExpression(expressionString: string): string;
}
//# sourceMappingURL=kos-expression-evaluator-model.d.ts.map