// Re-export core types and functions
// Import these only once below with the other re-exports
mod announce;
#[cfg(test)]
mod announce_tests;
#[cfg(test)]
mod bootstrap_tests;
#[cfg(all(test, feature = "database"))]
mod database_tests;
mod error;
#[cfg(test)]
mod feature_tests;
mod handshake;
mod ipc;
#[cfg(test)]
mod ipc_process_tests;
#[cfg(test)]
mod ipc_tests;
#[cfg(test)]
mod logging_tests;
#[cfg(test)]
mod router_discovery_tests;
#[cfg(test)]
mod server_tests;
mod state;
#[cfg(test)]
mod state_tests;

// Re-export moved modules and their key types/functions
pub mod ipc_types;
pub use ipc_types::{
    Announce as ModuleAnnounce,
    AnnounceBlob,
    ClientRequest,
    Endpoint as AnnouncedEndpoint,
    EndpointAnnounce,
    GetSecretRequest,
    // Legacy aliases
    Init as OrchestratorInit,
    InitBlob,
    ListenAddress,
    ModuleToOrchestrator,
    OrchestratorToModule,
    RotatedNotification,
    RotationAckRequest,
    SecretValueResponse,
    ServerResponse,
};

// Database module for standardized database access
#[cfg(feature = "database")]
pub mod database;
#[cfg(feature = "database")]
pub use database::{
    DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseResult, DatabaseRow,
    DatabaseTransaction, DatabaseType, DatabaseValue, create_database_connection, extensions,
};

// Cache module for standardized cache access
#[cfg(feature = "cache")]
pub mod cache;
#[cfg(feature = "cache")]
pub use cache::{
    CacheConfig, CacheError, CacheResult, CacheService, CacheStats, CacheType, create_cache_service,
};

// Conditionally include and re-export JWT auth functionality
#[cfg(feature = "jwt_auth")]
pub mod jwt_auth;

// Backward compatibility module for jwt_auth
#[cfg(feature = "jwt_auth")]
#[path = "jwt_auth_compat.rs"]
#[deprecated(since = "0.2.5", note = "Use the jwt_auth module directly")]
pub mod jwt_auth_compat;

// Conditionally include and re-export proc macros
#[cfg(feature = "proc_macros")]
pub mod pywatt_macros;
#[cfg(feature = "proc_macros")]
pub mod macros;

// Modules from merged crates
pub mod secret_client;
pub mod secret_provider;

// Original SDK modules
mod bootstrap;
pub mod build;
mod builder;
mod ext;
mod logging;
mod router_discovery;
mod secrets;
mod server;
pub mod typed_secret;
mod utils;

// Re-export functions & types from SDK modules
pub use announce::{AnnounceError, send_announce};
pub use bootstrap::{BootstrapError, bootstrap_module};
pub use builder::ModuleBuilder;
pub use error::{Error, Result};
pub use handshake::{InitError, read_init};
pub use ipc::process_ipc_messages;
pub use logging::init_module;
pub use router_discovery::announce_from_router;
pub use secrets::{get_module_secret_client, get_secret, get_secrets, subscribe_secret_rotations};
pub use server::{ServeError, serve_module};
pub use state::AppState;
pub use typed_secret::{Secret, TypedSecretError, get_typed_secret};
pub use utils::{eprint_json, eprint_pretty_json, print_json, print_pretty_json};

// Compatibility re-exports for backward compatibility
#[cfg(feature = "jwt_auth")]
/// Re-export JWT auth extension trait and layer at crate root
#[deprecated(since = "0.2.5", note = "Import from jwt_auth module directly")]
pub use crate::jwt_auth::{JwtAuthLayer, RouterJwtExt};

/// Re-export secret redaction helpers for backward compatibility
pub use crate::secret_client::{register_for_redaction, register_secret_for_redaction};

// Feature-gated re-exports
#[cfg(feature = "router_ext")]
pub use ext::RouterExt;

/// Prelude module, exposing the most commonly used items.
pub mod prelude {
    pub use crate::{
        AnnouncedEndpoint, AppState, Error, ModuleAnnounce, OrchestratorInit, Result, Secret,
        TypedSecretError, build, get_module_secret_client, get_secret, get_secrets,
        get_typed_secret, init_module, ipc_types, process_ipc_messages, read_init, send_announce,
        subscribe_secret_rotations,
    };

    // Database API
    #[cfg(feature = "database")]
    pub use crate::database::{
        DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseResult, DatabaseRow,
        DatabaseTransaction, DatabaseType, DatabaseValue, create_database_connection, extensions,
    };

    #[cfg(all(feature = "database", feature = "postgres"))]
    pub use crate::database::PostgresConnection;

    #[cfg(all(feature = "database", feature = "mysql"))]
    pub use crate::database::MySqlConnection;

    #[cfg(all(feature = "database", feature = "sqlite"))]
    pub use crate::database::SqliteConnection;

    // Cache API
    #[cfg(feature = "cache")]
    pub use crate::cache::{
        CacheConfig, CacheError, CacheResult, CacheService, CacheStats, CacheType,
        create_cache_service,
    };

    #[cfg(all(feature = "cache", feature = "redis_cache"))]
    pub use crate::cache::RedisCache;

    #[cfg(all(feature = "cache", feature = "memcached"))]
    pub use crate::cache::MemcachedCache;

    #[cfg(feature = "cache")]
    pub use crate::cache::InMemoryCache;

    #[cfg(all(feature = "cache", feature = "file_cache"))]
    pub use crate::cache::FileCache;

    #[cfg(feature = "cache")]
    pub use crate::cache::patterns::{
        DistributedLock, EventInvalidationStrategy, InvalidationStrategy, LockError,
        LruInvalidationStrategy, RetryConfig, TtlInvalidationStrategy, cache_aside, write_through,
    };

    // Secret client APIs
    pub use crate::secret_client::{RequestMode, SecretClient, SecretError as SecretClientError};

    // Secret provider APIs
    pub use crate::secret_provider::{
        SecretError as SecretProviderError, SecretEvent, SecretProvider,
    };

    #[cfg(feature = "jwt_auth")]
    pub use crate::jwt_auth::error::JwtAuthError;
    #[cfg(feature = "jwt_auth")]
    pub use crate::jwt_auth::middleware::JwtAuthenticationLayer;

    #[cfg(feature = "proc_macros")]
    pub use crate::pywatt_macros::*;

    #[cfg(feature = "router_ext")]
    pub use crate::ext::RouterExt;

    #[cfg(feature = "discover_endpoints")]
    pub use crate::router_discovery::announce_from_router;
}

pub mod model_manager;

// Re-export model_manager types
pub use model_manager::ModelManager;

// Add the test module
#[cfg(test)]
#[cfg(feature = "ipc")]
mod ipc_proxy_tests;
