"""Facades - Simplified interfaces for grouped agent features."""

from typing import Dict, Any


class MetricsFacade:
    """Simplified interface for agent metrics."""
    
    def __init__(self, metrics_collector):
        """Initialize metrics facade.
        
        Args:
            metrics_collector: ColectorMetricas instance
        """
        self.metrics_collector = metrics_collector
    
    def get_all(self) -> Dict[str, Any]:
        """Get all performance metrics."""
        return self.metrics_collector.obtener_estado()
    
    def get_avg_latency(self) -> float:
        """Get average latency in seconds."""
        return self.metrics_collector.obtener_latencia_promedio()
    
    def get_p95_latency(self) -> float:
        """Get 95th percentile latency."""
        return self.metrics_collector.obtener_latencia_p95()
    
    def get_throughput(self) -> float:
        """Get throughput: tasks per second."""
        return self.metrics_collector.obtener_throughput()
    
    def get_error_rate(self) -> float:
        """Get error rate (0.0 to 1.0)."""
        return self.metrics_collector.obtener_tasa_error()
    
    def clear(self):
        """Clear all metrics."""
        self.metrics_collector.limpiar()


class SecurityFacade:
    """Simplified interface for agent security."""
    
    def __init__(self, security_sandbox):
        """Initialize security facade.
        
        Args:
            security_sandbox: SandboxSeguridad instance
        """
        self.security_sandbox = security_sandbox
    
    def validate_task(self, task: str) -> bool:
        """Check if task is safe."""
        return self.security_sandbox.es_segura_tarea(task)
    
    def get_stats(self) -> Dict[str, Any]:
        """Get security validation statistics."""
        return self.security_sandbox.obtener_estadisticas_seguridad()
    
    def add_denylist_pattern(self, pattern: str):
        """Add forbidden pattern."""
        self.security_sandbox.agregar_denylist(pattern)
    
    def add_whitelist_pattern(self, pattern: str):
        """Add allowed pattern."""
        self.security_sandbox.agregar_whitelist(pattern)
    
    def set_whitelist_mode(self, enable: bool = True):
        """Enable or disable whitelist mode."""
        self.security_sandbox.habilitar_whitelist = enable
    
    def clear_stats(self):
        """Clear security counters."""
        self.security_sandbox.limpiar_estadisticas()


class HealthFacade:
    """Simplified interface for agent health probes."""
    
    def __init__(self, health_probe):
        """Initialize health facade.
        
        Args:
            health_probe: SondeoSalud instance
        """
        self.health_probe = health_probe
    
    def liveness(self) -> Dict[str, Any]:
        """Get liveness probe (is agent alive?)."""
        return self.health_probe.sondeo_liveness()
    
    def readiness(
        self,
        alive: bool,
        queue_size: int,
        capacity: int
    ) -> Dict[str, Any]:
        """Get readiness probe (is agent ready?)."""
        return self.health_probe.sondeo_readiness(alive, queue_size, capacity)
    
    def startup(self, alive: bool) -> Dict[str, Any]:
        """Get startup probe (did startup finish?)."""
        return self.health_probe.sondeo_startup(alive)
    
    def general(
        self,
        alive: bool,
        queue_size: int,
        capacity: int
    ) -> Dict[str, Any]:
        """Get general health state."""
        return self.health_probe.obtener_estado_general(alive, queue_size, capacity)
