//! Foxhunt API Service — unified gRPC gateway with tonic-web for browser access
//!
//! Provides zero-copy gRPC proxying with:
//! - RBAC authorization with sub-100ns cached permission checks
//! - <10us routing overhead
//! - Connection pooling
//! - Circuit breaker pattern
//! - Health checking
//! - Performance monitoring
//! - Token bucket rate limiting with <50ns cache hits
//! - gRPC-Web support for browser clients via tonic-web

#![deny(clippy::unwrap_used, clippy::expect_used)]
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
// API gateway domain lints: generated protobuf code and routing logic
#![allow(clippy::mixed_attributes_style)] // Generated protobuf code uses mixed attributes
#![allow(clippy::type_complexity)] // Complex types in async proxy handlers
#![allow(clippy::doc_lazy_continuation)] // Doc formatting acceptable
#![allow(clippy::manual_strip)] // Explicit prefix stripping for clarity

// File descriptor sets for gRPC reflection
pub const TLI_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("tli_descriptor");
pub const MONITORING_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("monitoring_descriptor");
pub const ML_TRAINING_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("ml_training_descriptor");
pub const TRADING_AGENT_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("trading_agent_descriptor");
pub const TRADING_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("trading_descriptor");
pub const RISK_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("risk_descriptor");
pub const CONFIG_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("config_descriptor");
pub const BROKER_GATEWAY_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("broker_gateway_descriptor");
pub const DATA_ACQUISITION_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("data_acquisition_descriptor");
pub const ML_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("ml_descriptor");
pub const AUTH_FILE_DESCRIPTOR_SET: &[u8] =
    tonic::include_file_descriptor_set!("auth_descriptor");

// Include generated protobuf code FIRST (needed by other modules)
pub mod foxhunt {
    pub mod tli {
        tonic::include_proto!("foxhunt.tli");
    }
}

pub mod ml_training {
    tonic::include_proto!("ml_training");
}

// Trading Agent Service proto (for proxy)
pub mod trading_agent {
    tonic::include_proto!("trading_agent");
}

// Trading Service backend proto (for protocol translation)
pub mod trading_backend {
    tonic::include_proto!("trading");
}

// Risk Service backend proto
pub mod risk {
    tonic::include_proto!("risk");
}

// Monitoring Service backend proto
pub mod monitoring {
    tonic::include_proto!("monitoring");
}

// Config Service backend proto
pub mod config_backend {
    tonic::include_proto!("config");
}

// Broker Gateway Service proto
pub mod broker_gateway {
    tonic::include_proto!("broker_gateway");
}

// Data Acquisition Service proto
pub mod data_acquisition {
    tonic::include_proto!("data_acquisition");
}

// ML Inference Service proto
pub mod ml_inference {
    tonic::include_proto!("ml");
}

// Auth Service proto (server-only, unauthenticated)
pub mod auth_proto {
    tonic::include_proto!("auth");
}

// Error module MUST come before modules that use it
pub mod error;

// Now other modules can use error types and proto definitions
pub mod auth;
pub mod config;
pub mod grpc;
pub mod health_router;
pub mod metrics;
pub mod routing;

// Re-export error types
pub use error::{GatewayConfigError, GatewayConfigResult};

// Re-export configuration management types
pub use config::{
    AuthzMetrics, AuthzService, ConfigItem, ConfigValidator, ConfigurationManager,
    GatewayConfigService, PermissionResult,
};

// Re-export routing and rate limiting types
pub use routing::{CacheStats, RateLimitConfig, RateLimiter};

// Re-export gRPC proxy and handler types
pub use grpc::{
    setup_ml_training_client, setup_ml_training_proxy, setup_trading_agent_client,
    setup_trading_agent_proxy, BackendHealthState, BacktestingServiceProxy, BrokerGatewayProxy,
    ConfigServiceProxy, DataAcquisitionProxy, HealthChecker, MlServiceProxy, MlTradingProxy,
    MlTrainingBackendConfig, MlTrainingProxy, MonitoringServiceHandler, RiskServiceProxy,
    ServiceHealthEntry, TradingAgentBackendConfig, TradingAgentProxy, TradingDirectProxy,
    TradingServiceProxy,
};

// Re-export health router types
pub use health_router::{health_router, HealthState};

