import type { Intent, ControlAction, ID, Timestamp, TrustLevel, TrustScore } from '../common/types.js';
/**
 * Policy version metadata
 */
export interface PolicyVersion {
    /** Version number */
    version: string;
    /** Who created this version */
    createdBy: string;
    /** When this version was created */
    createdAt: Timestamp;
    /** Change description */
    description?: string;
    /** Previous version ID (for rollback) */
    previousVersionId?: ID;
}
/**
 * Constraint template for reusable policy patterns
 */
export interface ConstraintTemplate {
    /** Unique template identifier */
    id: ID;
    /** Template name */
    name: string;
    /** Template description */
    description: string;
    /** Parameters that can be customized */
    parameters: TemplateParameter[];
    /** The constraint expression template */
    expression: string;
    /** Tags for categorization */
    tags: string[];
    /** Template version */
    version: string;
}
/**
 * Template parameter definition
 */
export interface TemplateParameter {
    /** Parameter name */
    name: string;
    /** Parameter type */
    type: 'string' | 'number' | 'boolean' | 'array' | 'object';
    /** Default value */
    defaultValue?: unknown;
    /** Whether parameter is required */
    required: boolean;
    /** Description */
    description?: string;
    /** Validation constraints */
    validation?: {
        min?: number;
        max?: number;
        pattern?: string;
        enum?: unknown[];
    };
}
/**
 * Enforcement policy definition
 */
export interface EnforcementPolicy {
    /** Unique policy identifier */
    id: ID;
    /** Policy name */
    name: string;
    /** Policy description */
    description?: string;
    /** Policy rules */
    rules: PolicyRule[];
    /** Default action when no rules match */
    defaultAction: ControlAction;
    /** Policy priority (lower = higher priority) */
    priority: number;
    /** Whether policy is enabled */
    enabled: boolean;
    /** Policy conditions for applicability */
    conditions?: PolicyConditions;
    /** Version information */
    version: PolicyVersion;
    /** Metadata */
    metadata?: Record<string, unknown>;
    /** Creation timestamp */
    createdAt: Timestamp;
    /** Last update timestamp */
    updatedAt: Timestamp;
}
/**
 * Policy rule definition
 */
export interface PolicyRule {
    /** Rule identifier */
    id: ID;
    /** Rule name */
    name: string;
    /** Condition expression */
    condition: RuleCondition;
    /** Action when condition matches */
    action: ControlAction;
    /** Additional constraints to apply */
    constraints?: string[];
    /** Rule priority within policy */
    priority: number;
    /** Whether rule is enabled */
    enabled: boolean;
}
/**
 * Rule condition definition
 */
export interface RuleCondition {
    /** Condition type */
    type: 'expression' | 'template' | 'composite';
    /** Expression string (for expression type) */
    expression?: string;
    /** Template reference (for template type) */
    templateId?: ID;
    /** Template parameters */
    templateParams?: Record<string, unknown>;
    /** Sub-conditions (for composite type) */
    conditions?: RuleCondition[];
    /** Logic for combining sub-conditions */
    logic?: 'AND' | 'OR';
}
/**
 * Policy conditions for when policy applies
 */
export interface PolicyConditions {
    /** Required trust levels */
    trustLevels?: TrustLevel[];
    /** Action patterns to match */
    actionPatterns?: string[];
    /** Resource patterns to match */
    resourcePatterns?: string[];
    /** Intent type patterns */
    intentTypes?: string[];
    /** Entity types */
    entityTypes?: string[];
    /** Time-based conditions */
    timeConditions?: TimeCondition[];
}
/**
 * Time-based condition
 */
export interface TimeCondition {
    /** Start hour (0-23) */
    startHour?: number;
    /** End hour (0-23) */
    endHour?: number;
    /** Days of week (0 = Sunday) */
    daysOfWeek?: number[];
    /** Timezone */
    timezone?: string;
}
/**
 * Policy evaluation result
 */
export interface PolicyEvaluationResult {
    /** Policy that was evaluated */
    policyId: ID;
    /** Policy name */
    policyName: string;
    /** Whether policy matched */
    matched: boolean;
    /** Resulting action */
    action: ControlAction;
    /** Rules that were evaluated */
    rulesEvaluated: RuleEvaluationResult[];
    /** Matched rules */
    matchedRules: RuleEvaluationResult[];
    /** Applied constraints */
    appliedConstraints: string[];
    /** Evaluation duration */
    durationMs: number;
    /** Evaluation timestamp */
    evaluatedAt: Timestamp;
}
/**
 * Rule evaluation result
 */
export interface RuleEvaluationResult {
    /** Rule ID */
    ruleId: ID;
    /** Rule name */
    ruleName: string;
    /** Whether rule matched */
    matched: boolean;
    /** Resulting action */
    action: ControlAction;
    /** Reason for result */
    reason?: string;
    /** Evaluation details */
    details?: Record<string, unknown>;
}
/**
 * Context for policy evaluation
 */
export interface PolicyEvaluationContext {
    /** The intent being evaluated */
    intent: Intent;
    /** Trust score */
    trustScore: TrustScore;
    /** Trust level */
    trustLevel: TrustLevel;
    /** Additional context data */
    context?: Record<string, unknown>;
    /** Environment data */
    environment?: {
        timestamp: Timestamp;
        timezone: string;
    };
}
/**
 * Policy engine configuration options
 */
export interface PolicyEngineOptions {
    /** Default action when no policies match */
    defaultAction?: ControlAction;
    /** Enable OpenTelemetry tracing */
    enableTracing?: boolean;
    /** Maximum policies to evaluate */
    maxPolicies?: number;
    /** Enable policy caching */
    enableCaching?: boolean;
    /** Cache TTL in milliseconds */
    cacheTtlMs?: number;
}
/**
 * PolicyEngine class for evaluating enforcement policies
 */
export declare class PolicyEngine {
    private policies;
    private templates;
    private policyVersions;
    private options;
    private updateListeners;
    constructor(options?: PolicyEngineOptions);
    /**
     * Evaluate an intent against all applicable policies
     */
    evaluate(context: PolicyEvaluationContext): PolicyEvaluationResult[];
    /**
     * Evaluate with OpenTelemetry tracing
     */
    evaluateWithTracing(context: PolicyEvaluationContext): Promise<PolicyEvaluationResult[]>;
    /**
     * Determine the final action from evaluation results
     */
    determineFinalAction(results: PolicyEvaluationResult[]): ControlAction;
    /**
     * Evaluate a single policy
     */
    private evaluatePolicy;
    /**
     * Evaluate a single rule
     */
    private evaluateRule;
    /**
     * Evaluate a condition
     */
    private evaluateCondition;
    /**
     * Evaluate an expression condition
     */
    private evaluateExpression;
    /**
     * Evaluate a template-based condition
     */
    private evaluateTemplate;
    /**
     * Evaluate composite conditions
     */
    private evaluateComposite;
    /**
     * Resolve a field path from context
     */
    private resolveFieldPath;
    /**
     * Parse a value string into its proper type
     */
    private parseValue;
    /**
     * Compare values using operator
     */
    private compareValues;
    /**
     * Get applicable policies for context
     */
    private getApplicablePolicies;
    /**
     * Check if a policy is applicable to the context
     */
    private isPolicyApplicable;
    /**
     * Match a value against a pattern (supports wildcards)
     */
    private matchPattern;
    /**
     * Check time-based condition
     */
    private checkTimeCondition;
    /**
     * Add a policy
     */
    addPolicy(policy: EnforcementPolicy): void;
    /**
     * Update a policy (creates new version)
     */
    updatePolicy(policyId: ID, updates: Partial<EnforcementPolicy>, versionInfo: Omit<PolicyVersion, 'previousVersionId'>): void;
    /**
     * Remove a policy
     */
    removePolicy(policyId: ID): boolean;
    /**
     * Get a policy by ID
     */
    getPolicy(policyId: ID): EnforcementPolicy | undefined;
    /**
     * Get all policies
     */
    getAllPolicies(): EnforcementPolicy[];
    /**
     * Get enabled policies
     */
    getEnabledPolicies(): EnforcementPolicy[];
    /**
     * Get policy version history
     */
    getPolicyVersions(policyId: ID): PolicyVersion[];
    /**
     * Rollback policy to previous version
     */
    rollbackPolicy(policyId: ID): boolean;
    /**
     * Add a constraint template
     */
    addTemplate(template: ConstraintTemplate): void;
    /**
     * Remove a template
     */
    removeTemplate(templateId: ID): boolean;
    /**
     * Get a template by ID
     */
    getTemplate(templateId: ID): ConstraintTemplate | undefined;
    /**
     * Get all templates
     */
    getAllTemplates(): ConstraintTemplate[];
    /**
     * Find templates by tag
     */
    findTemplatesByTag(tag: string): ConstraintTemplate[];
    /**
     * Register an update listener
     */
    onPolicyUpdate(listener: (policyId: ID, action: 'add' | 'update' | 'remove') => void): () => void;
    /**
     * Notify listeners of policy updates
     */
    private notifyListeners;
    /**
     * Clear all policies and templates
     */
    clear(): void;
    /**
     * Get engine statistics
     */
    getStats(): {
        totalPolicies: number;
        enabledPolicies: number;
        totalTemplates: number;
        totalVersions: number;
    };
}
/**
 * Create a new policy engine instance
 */
export declare function createPolicyEngine(options?: PolicyEngineOptions): PolicyEngine;
/**
 * Create a new enforcement policy with defaults
 */
export declare function createEnforcementPolicy(partial: Partial<EnforcementPolicy> & Pick<EnforcementPolicy, 'id' | 'name' | 'rules'>): EnforcementPolicy;
//# sourceMappingURL=policy-engine.d.ts.map