"""
Enterprise Module - Minimal Code Patterns for Production AI Applications.

This module provides enterprise-grade decorators, factories, and blueprints
that enable developers to create complete AI applications with minimal code.

Features:
- Decorators: @agent, @workflow, @tool, @guardrail, @pipeline
- Factories: AgentFactory, WorkflowFactory, SDLCFactory
- Blueprints: Pre-built agents for common SDLC phases
- Adapters: Unified interfaces for cloud providers
- Presets: Enterprise configurations for common scenarios

Quick Start:
    >>> from agenticaiframework.enterprise import create_sdlc_pipeline, agent, workflow
    >>> 
    >>> # Create complete SDLC pipeline in 3 lines
    >>> pipeline = create_sdlc_pipeline("my-project")
    >>> result = await pipeline.run("Build an e-commerce platform")
    >>> print(result.artifacts)
    
    >>> # Or use decorators for custom agents
    >>> @agent(role="analyst", model="gpt-4o")
    >>> class MyAnalyst:
    ...     async def analyze(self, data: str) -> dict:
    ...         return await self.invoke(f"Analyze: {data}")
"""

__version__ = "1.0.0"

# Decorators
from .decorators import (
    agent,
    workflow,
    tool,
    guardrail,
    pipeline,
    step,
    retry,
    timeout,
    trace,
    cache,
    validate,
    authorize,
)

# Factories
from .factories import (
    AgentFactory,
    WorkflowFactory,
    PipelineFactory,
    ToolFactory,
    create_agent,
    create_workflow,
    create_pipeline,
)

# Blueprints (Pre-built agents)
from .blueprints import (
    # SDLC Agents
    RequirementsAgent,
    DesignAgent,
    DevelopmentAgent,
    TestingAgent,
    SecurityAgent,
    DeploymentAgent,
    DocumentationAgent,
    ReviewAgent,
    # Other common agents
    AnalystAgent,
    ResearcherAgent,
    WriterAgent,
    # Blueprints helpers
    get_blueprint,
    list_blueprints,
)

# SDLC Pipeline (Complete solution)
from .sdlc import (
    SDLCPipeline,
    SDLCPhase,
    SDLCArtifact,
    SDLCConfig,
    SDLCResult,
    create_sdlc_pipeline,
)

# Adapters
from .adapters import (
    StorageAdapter,
    LLMAdapter,
    VectorDBAdapter,
    CacheAdapter,
    # Cloud-specific
    AzureAdapter,
    AWSAdapter,
    GCPAdapter,
    get_adapter,
)

# Presets
from .presets import (
    EnterprisePreset,
    StartupPreset,
    DevelopmentPreset,
    ProductionPreset,
    TestingPreset,
    MinimalPreset,
    load_preset,
    list_presets,
    auto_preset,
)

# Utils
from .utils import (
    AsyncContextMixin,
    StreamingResponse,
    stream_response,
    BatchProcessor,
    BatchResult,
    ProgressTracker,
    CancellationToken,
    retry_with_backoff,
    CircuitBreaker,
    RateLimiter,
    KeyedRateLimiter,
    ConnectionPool,
    AsyncCache,
    cached,
    StructuredLogger,
    HealthChecker,
    HealthStatus,
    MetricsCollector,
)

# Middleware
from .middleware import (
    Request,
    Response,
    Middleware,
    MiddlewarePipeline,
    LoggingMiddleware,
    MetricsMiddleware,
    AuthMiddleware,
    RateLimitMiddleware,
    CachingMiddleware,
    RetryMiddleware,
    TracingMiddleware,
    ValidationMiddleware,
    HooksManager,
    HookType,
    create_standard_pipeline,
    create_secure_pipeline,
    create_cached_pipeline,
)

# Events
from .events import (
    Event,
    EventType,
    EventBus,
    EventAggregator,
    EventStore,
    InMemoryEventStore,
    TypedEvent,
    global_event_bus,
    on_event,
    emit_event,
    emit_agent_started,
    emit_agent_completed,
    emit_agent_failed,
)

# Dependency Injection
from .di import (
    Container,
    Scope,
    Lifetime,
    ServiceCollection,
    ServiceProvider,
    inject,
    inject_async,
    singleton,
    transient,
    scoped,
    resolve,
    get_container,
    set_container,
    DependencyError,
)

# Plugins
from .plugins import (
    Plugin,
    PluginMetadata,
    PluginStatus,
    PluginRegistry,
    PluginLoader,
    PluginManager,
    plugin,
    get_plugin_registry,
    register_plugin,
    get_plugin,
    PluginError,
)

# Secrets
from .secrets import (
    Secret,
    SecretType,
    SecretBackend,
    EnvironmentBackend,
    InMemoryBackend,
    AzureKeyVaultBackend,
    SecretManager,
    get_secret_manager,
    get_secret,
    set_secret,
    rotate_secret,
    secret_from_env,
    mask_secret,
    generate_secret,
)

# Audit
from .audit import (
    AuditEntry,
    AuditAction,
    AuditSeverity,
    AuditBackend,
    InMemoryAuditBackend,
    FileAuditBackend,
    AuditLogger,
    get_audit_logger,
    audit_log,
    audit_track,
)

# RBAC
from .rbac import (
    Action,
    ResourceType,
    Permission,
    Role,
    Principal,
    Policy,
    AccessDecision,
    RBACManager,
    ROLE_ADMIN,
    ROLE_OPERATOR,
    ROLE_DEVELOPER,
    ROLE_VIEWER,
    ROLE_AGENT,
    get_current_principal,
    set_current_principal,
    PrincipalContext,
    get_rbac_manager,
    check_access,
    require_access,
)

# Templates
from .templates import (
    PromptTemplate,
    TemplateType,
    TemplateVariable,
    TemplateLibrary,
    TemplateBuilder,
    template,
    get_template_library,
    render_template,
    register_template,
    get_template,
)

# Feature Flags
from .feature_flags import (
    FeatureFlag,
    FlagType,
    RolloutStrategy,
    FlagVariant,
    FlagContext,
    FlagEvaluation,
    FlagBackend,
    InMemoryFlagBackend,
    FlagEvaluator,
    FeatureFlags,
    feature_flag,
    get_feature_flags,
    is_enabled,
    get_flag_value,
    get_variant,
)

# Multi-tenancy
from .multitenancy import (
    Tenant,
    TenantStatus,
    TenantTier,
    TenantQuota,
    TenantUsage,
    TenantStore,
    InMemoryTenantStore,
    TenantManager,
    TenantContext,
    TenantIsolation,
    TenantMiddleware,
    get_tenant_manager,
    get_current_tenant,
    require_tenant,
    check_quota,
    require_feature,
)

# Streaming
from .streaming import (
    StreamEventType,
    StreamEvent,
    StreamSource,
    LLMStreamSource,
    StreamProcessor,
    StreamAccumulator,
    StreamMultiplexer,
    SSEFormatter,
    JSONLFormatter,
    MarkdownFormatter,
    stream_to_string,
    stream_with_progress,
    stream_with_display,
    StreamBuilder,
)

# Cost Estimation
from .cost import (
    ModelPricing,
    TokenCounter,
    TiktokenCounter,
    ApproximateCounter,
    get_token_counter,
    UsageRecord,
    CostEstimator,
    CostEstimate,
    UsageTracker,
    UsageSummary,
    get_usage_tracker,
    set_usage_tracker,
    track_usage,
    get_usage_summary,
    estimate_cost,
    count_tokens,
)

# JSON Mode
from .json_mode import (
    python_type_to_json_schema,
    generate_json_schema,
    JSONExtractor,
    JSONRepairer,
    JSONResponse,
    JSONMode,
    json_output,
    TextWithConfidence,
    EntityExtraction,
    Classification,
    Sentiment,
    Summary,
    Translation,
    CodeGeneration,
    StructuredAnswer,
    create_json_mode,
    extract_json,
    repair_json,
    schema_from_model,
)

# State Management
from .state import (
    StateStatus,
    StateMetadata,
    StateEntry,
    StateStore,
    InMemoryStateStore,
    FileStateStore,
    Checkpoint,
    CheckpointManager,
    StateManager,
    ScopedStateManager,
    StateTransaction,
    get_state_manager,
    set_state_manager,
    get_state,
    set_state,
    delete_state,
    stateful,
)

# Parallel Execution
from .parallel import (
    TaskStatus,
    TaskPriority,
    ParallelTask,
    TaskResult,
    ResourcePool,
    ResourceContext,
    DAGExecutor,
    parallel_map,
    parallel_batch,
    parallel_step,
    collect_parallel_steps,
    ExecutionProgress,
    ProgressTracker as ParallelProgressTracker,
    create_dag,
    task,
    run_parallel,
    run_with_timeout,
)

# Distributed Tracing (OpenTelemetry)
from .tracing_otel import (
    SpanKind,
    SpanStatus,
    SpanContext,
    SpanEvent,
    Span,
    SpanExporter,
    ConsoleExporter,
    InMemoryExporter,
    OTLPExporter,
    Tracer,
    get_tracer,
    set_tracer,
    configure_tracing,
    trace as otel_trace,
    trace_agent,
    inject_context,
    extract_context,
    with_context,
    AgentTracer,
    start_span,
    end_span,
    current_trace_id,
    current_span_id,
)

# Metrics Export
from .metrics import (
    MetricType,
    MetricLabel,
    MetricValue,
    Metric,
    Counter,
    Gauge,
    Histogram,
    Timer,
    MetricsRegistry,
    MetricsExporter,
    PrometheusExporter,
    StatsDExporter,
    get_metrics_registry,
    set_metrics_registry,
    AgentMetrics,
    with_metrics,
    start_metrics_server,
)

# Workflow DSL
from .dsl import (
    NodeType,
    ConditionOperator,
    Condition,
    WorkflowNode,
    AgentNode,
    ToolNode,
    ConditionNode,
    LoopNode,
    ParallelNode,
    HumanNode,
    TransformNode,
    WorkflowDefinition,
    WorkflowBuilder,
    ConditionBuilder,
    ParallelBuilder,
    LoopBuilder,
    WorkflowParser,
    workflow as dsl_workflow,
    parse_workflow,
)

# Agent Composition
from .composition import (
    ComponentStatus,
    ComponentMetadata,
    Component,
    MemoryTrait,
    ToolsTrait,
    ObservableTrait,
    ReflectionTrait,
    ComposableAgent,
    InputValidator,
    OutputFormatter,
    LoggingComponent,
    TransformComponent,
    FilterComponent,
    CacheComponent,
    AgentPipeline,
    ComposableAgentFactory,
    AgentBuilder,
    component,
    composable,
    create_pipeline as create_agent_pipeline,
    compose,
)

# API Generator
from .api_gen import (
    SchemaObject,
    ParameterObject,
    RequestBodyObject,
    ResponseObject,
    OperationObject,
    PathItemObject,
    OpenAPISpec,
    SchemaConverter,
    APIGenerator,
    api_endpoint,
    create_fastapi_app,
    register_agent_routes,
    generate_openapi,
    save_openapi_spec,
)

__all__ = [
    # Decorators
    "agent",
    "workflow",
    "tool",
    "guardrail",
    "pipeline",
    "step",
    "retry",
    "timeout",
    "trace",
    "cache",
    "validate",
    "authorize",
    # Factories
    "AgentFactory",
    "WorkflowFactory",
    "PipelineFactory",
    "ToolFactory",
    "create_agent",
    "create_workflow",
    "create_pipeline",
    # Blueprints
    "RequirementsAgent",
    "DesignAgent",
    "DevelopmentAgent",
    "TestingAgent",
    "SecurityAgent",
    "DeploymentAgent",
    "DocumentationAgent",
    "ReviewAgent",
    "AnalystAgent",
    "ResearcherAgent",
    "WriterAgent",
    "get_blueprint",
    "list_blueprints",
    # SDLC
    "SDLCPipeline",
    "SDLCPhase",
    "SDLCArtifact",
    "SDLCConfig",
    "SDLCResult",
    "create_sdlc_pipeline",
    # Adapters
    "StorageAdapter",
    "LLMAdapter",
    "VectorDBAdapter",
    "CacheAdapter",
    "AzureAdapter",
    "AWSAdapter",
    "GCPAdapter",
    "get_adapter",
    # Presets
    "EnterprisePreset",
    "StartupPreset",
    "DevelopmentPreset",
    "ProductionPreset",
    "TestingPreset",
    "MinimalPreset",
    "load_preset",
    "list_presets",
    "auto_preset",
    # Utils
    "AsyncContextMixin",
    "StreamingResponse",
    "stream_response",
    "BatchProcessor",
    "BatchResult",
    "ProgressTracker",
    "CancellationToken",
    "retry_with_backoff",
    "CircuitBreaker",
    "RateLimiter",
    "KeyedRateLimiter",
    "ConnectionPool",
    "AsyncCache",
    "cached",
    "StructuredLogger",
    "HealthChecker",
    "HealthStatus",
    "MetricsCollector",
    # Middleware
    "Request",
    "Response",
    "Middleware",
    "MiddlewarePipeline",
    "LoggingMiddleware",
    "MetricsMiddleware",
    "AuthMiddleware",
    "RateLimitMiddleware",
    "CachingMiddleware",
    "RetryMiddleware",
    "TracingMiddleware",
    "ValidationMiddleware",
    "HooksManager",
    "HookType",
    "create_standard_pipeline",
    "create_secure_pipeline",
    "create_cached_pipeline",
    # Events
    "Event",
    "EventType",
    "EventBus",
    "EventAggregator",
    "EventStore",
    "InMemoryEventStore",
    "TypedEvent",
    "global_event_bus",
    "on_event",
    "emit_event",
    "emit_agent_started",
    "emit_agent_completed",
    "emit_agent_failed",
    # Dependency Injection
    "Container",
    "Scope",
    "Lifetime",
    "ServiceCollection",
    "ServiceProvider",
    "inject",
    "inject_async",
    "singleton",
    "transient",
    "scoped",
    "resolve",
    "get_container",
    "set_container",
    "DependencyError",
    # Plugins
    "Plugin",
    "PluginMetadata",
    "PluginStatus",
    "PluginRegistry",
    "PluginLoader",
    "PluginManager",
    "plugin",
    "get_plugin_registry",
    "register_plugin",
    "get_plugin",
    "PluginError",
    # Secrets
    "Secret",
    "SecretType",
    "SecretBackend",
    "EnvironmentBackend",
    "InMemoryBackend",
    "AzureKeyVaultBackend",
    "SecretManager",
    "get_secret_manager",
    "get_secret",
    "set_secret",
    "rotate_secret",
    "secret_from_env",
    "mask_secret",
    "generate_secret",
    # Audit
    "AuditEntry",
    "AuditAction",
    "AuditSeverity",
    "AuditBackend",
    "InMemoryAuditBackend",
    "FileAuditBackend",
    "AuditLogger",
    "get_audit_logger",
    "audit_log",
    "audit_track",
    # RBAC
    "Action",
    "ResourceType",
    "Permission",
    "Role",
    "Principal",
    "Policy",
    "AccessDecision",
    "RBACManager",
    "ROLE_ADMIN",
    "ROLE_OPERATOR",
    "ROLE_DEVELOPER",
    "ROLE_VIEWER",
    "ROLE_AGENT",
    "get_current_principal",
    "set_current_principal",
    "PrincipalContext",
    "get_rbac_manager",
    "check_access",
    "require_access",
    # Templates
    "PromptTemplate",
    "TemplateType",
    "TemplateVariable",
    "TemplateLibrary",
    "TemplateBuilder",
    "template",
    "get_template_library",
    "render_template",
    "register_template",
    "get_template",
    # Feature Flags
    "FeatureFlag",
    "FlagType",
    "RolloutStrategy",
    "FlagVariant",
    "FlagContext",
    "FlagEvaluation",
    "FlagBackend",
    "InMemoryFlagBackend",
    "FlagEvaluator",
    "FeatureFlags",
    "feature_flag",
    "get_feature_flags",
    "is_enabled",
    "get_flag_value",
    "get_variant",
    # Multi-tenancy
    "Tenant",
    "TenantStatus",
    "TenantTier",
    "TenantQuota",
    "TenantUsage",
    "TenantStore",
    "InMemoryTenantStore",
    "TenantManager",
    "TenantContext",
    "TenantIsolation",
    "TenantMiddleware",
    "get_tenant_manager",
    "get_current_tenant",
    "require_tenant",
    "check_quota",
    "require_feature",
    # Streaming
    "StreamEventType",
    "StreamEvent",
    "StreamSource",
    "LLMStreamSource",
    "StreamProcessor",
    "StreamAccumulator",
    "StreamMultiplexer",
    "SSEFormatter",
    "JSONLFormatter",
    "MarkdownFormatter",
    "stream_to_string",
    "stream_with_progress",
    "stream_with_display",
    "StreamBuilder",
    # Cost Estimation
    "ModelPricing",
    "TokenCounter",
    "TiktokenCounter",
    "ApproximateCounter",
    "get_token_counter",
    "UsageRecord",
    "CostEstimator",
    "CostEstimate",
    "UsageTracker",
    "UsageSummary",
    "get_usage_tracker",
    "set_usage_tracker",
    "track_usage",
    "get_usage_summary",
    "estimate_cost",
    "count_tokens",
    # JSON Mode
    "python_type_to_json_schema",
    "generate_json_schema",
    "JSONExtractor",
    "JSONRepairer",
    "JSONResponse",
    "JSONMode",
    "json_output",
    "TextWithConfidence",
    "EntityExtraction",
    "Classification",
    "Sentiment",
    "Summary",
    "Translation",
    "CodeGeneration",
    "StructuredAnswer",
    "create_json_mode",
    "extract_json",
    "repair_json",
    "schema_from_model",
    # State Management
    "StateStatus",
    "StateMetadata",
    "StateEntry",
    "StateStore",
    "InMemoryStateStore",
    "FileStateStore",
    "Checkpoint",
    "CheckpointManager",
    "StateManager",
    "ScopedStateManager",
    "StateTransaction",
    "get_state_manager",
    "set_state_manager",
    "get_state",
    "set_state",
    "delete_state",
    "stateful",
    # Parallel Execution
    "TaskStatus",
    "TaskPriority",
    "ParallelTask",
    "TaskResult",
    "ResourcePool",
    "ResourceContext",
    "DAGExecutor",
    "parallel_map",
    "parallel_batch",
    "parallel_step",
    "collect_parallel_steps",
    "ExecutionProgress",
    "ParallelProgressTracker",
    "create_dag",
    "task",
    "run_parallel",
    "run_with_timeout",
    # Distributed Tracing
    "SpanKind",
    "SpanStatus",
    "SpanContext",
    "SpanEvent",
    "Span",
    "SpanExporter",
    "ConsoleExporter",
    "InMemoryExporter",
    "OTLPExporter",
    "Tracer",
    "get_tracer",
    "set_tracer",
    "configure_tracing",
    "otel_trace",
    "trace_agent",
    "inject_context",
    "extract_context",
    "with_context",
    "AgentTracer",
    "start_span",
    "end_span",
    "current_trace_id",
    "current_span_id",
    # Metrics Export
    "MetricType",
    "MetricLabel",
    "MetricValue",
    "Metric",
    "Counter",
    "Gauge",
    "Histogram",
    "Timer",
    "MetricsRegistry",
    "MetricsExporter",
    "PrometheusExporter",
    "StatsDExporter",
    "get_metrics_registry",
    "set_metrics_registry",
    "AgentMetrics",
    "with_metrics",
    "start_metrics_server",
    # Workflow DSL
    "NodeType",
    "ConditionOperator",
    "Condition",
    "WorkflowNode",
    "AgentNode",
    "ToolNode",
    "ConditionNode",
    "LoopNode",
    "ParallelNode",
    "HumanNode",
    "TransformNode",
    "WorkflowDefinition",
    "WorkflowBuilder",
    "ConditionBuilder",
    "ParallelBuilder",
    "LoopBuilder",
    "WorkflowParser",
    "dsl_workflow",
    "parse_workflow",
    # Agent Composition
    "ComponentStatus",
    "ComponentMetadata",
    "Component",
    "MemoryTrait",
    "ToolsTrait",
    "ObservableTrait",
    "ReflectionTrait",
    "ComposableAgent",
    "InputValidator",
    "OutputFormatter",
    "LoggingComponent",
    "TransformComponent",
    "FilterComponent",
    "CacheComponent",
    "AgentPipeline",
    "ComposableAgentFactory",
    "AgentBuilder",
    "component",
    "composable",
    "create_agent_pipeline",
    "compose",
    # API Generator
    "SchemaObject",
    "ParameterObject",
    "RequestBodyObject",
    "ResponseObject",
    "OperationObject",
    "PathItemObject",
    "OpenAPISpec",
    "SchemaConverter",
    "APIGenerator",
    "api_endpoint",
    "create_fastapi_app",
    "register_agent_routes",
    "generate_openapi",
    "save_openapi_spec",
]
