//! # Athena Auth - Rust
//!
//! An authentication framework pure in rust for Athena
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use athena_auth::{AuthBuilder, AuthConfig};
//! use athena_auth::adapters::MemoryDatabaseAdapter;
//! use athena_auth::plugins::EmailPasswordPlugin;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let config = AuthConfig::new("your-secret-key-that-is-at-least-32-chars");
//!
//!     let auth = AuthBuilder::new(config)
//!         .database(MemoryDatabaseAdapter::new())
//!         .plugin(EmailPasswordPlugin::new())
//!         .build()
//!         .await?;
//!
//!     Ok(())
//! }
//! ```

// Core module — AthenaAuth struct lives here in the root crate
// because it orchestrates plugins (from athena-auth-api) + core (from athena-auth-core)
pub mod core;
pub mod handlers;

// Re-export core abstractions
pub use athena_auth_core as types_mod;
pub use athena_auth_core::{
    Account, AccountOps, AdminAuditLog, Argon2Config, AthenaClient, AuthConfig, AuthContext,
    AuthEmailEventCatalogEntry, AuthError, AuthPlugin, AuthRequest, AuthResponse, AuthResult,
    AuthRoute, AvatarStorageConfig, AvatarStorageUrlStyle, BodyLimitConfig, BodyLimitMiddleware,
    CacheAdapter, ConsoleEmailProvider, CookieCacheConfig, CookieCacheStrategy, CorsConfig,
    CorsMiddleware, CreateAccount, CreateAdminAuditLog, CreateAthenaClient, CreateEmailSendFailure,
    CreateEmailTemplate, CreateInvitation, CreateMember, CreateOrganization, CreatePasskey,
    CreateSentEmail, CreateSession, CreateSessionIpProfileRecord, CreateUser, CreateVerification,
    CsrfConfig, CsrfMiddleware, DatabaseAdapter, DatabaseError, DatabaseHooks,
    DatabaseLoggingEmailProvider, EmailEventType, EmailProvider, EmailSendFailure, EmailTemplate,
    EndpointRateLimit, GeoIpConfig, GeoIpProvider, HookedDatabaseAdapter, HttpMethod, Invitation,
    InvitationOps, InvitationStatus, IpProfileRecord, JwtConfig, ListAdminAuditLogsParams,
    ListEmailEventTypesParams, ListEmailSendFailuresParams, ListEmailTemplatesParams,
    ListSentEmailsParams, MemberOps, MemoryAccount, MemoryCacheAdapter, MemoryDatabaseAdapter,
    MemoryInvitation, MemoryMember, MemoryOrganization, MemorySession, MemoryUser,
    MemoryVerification, Middleware, OpenApiBuilder, OpenApiSpec, OrganizationOps,
    OriginTrustCurrentRequest, OriginTrustDebugSnapshot, OriginTrustRuntimeSnapshot,
    OriginTrustSourceHeader, OriginTrustViolationAttempt, OriginTrustViolationPhase, Passkey,
    PasskeyOps, PasswordConfig, RateLimitConfig, RateLimitMiddleware, SameSite, SentEmail, Session,
    SessionConfig, SessionCreateOptions, SessionIntelligenceConfig, SessionIpProfileRecord,
    SessionManager, SessionOps, SessionUserCache, TwoFactor, UpdateEmailSendFailure,
    UpdateEmailTemplate, UpdateOrganization, UpdatePasskey, UpdateSentEmail, UpdateUser,
    UpdateUserRequest, UpdateUserResponse, UpsertIpProfileRecord, User, UserOps, Verification,
    VerificationOps, auth_email_event_catalog, build_origin_trust_runtime_snapshot, core_paths,
    default_event_type_for_template_key, default_template_key_for_event_type,
    describe_origin_trust_for_headers, maybe_record_suppressed_cors_attempt,
    normalize_ip_address_value, record_origin_trust_violation, resolve_client_ip_from_headers,
    snapshot_origin_trust_debug,
};

#[cfg(feature = "smtp")]
pub use athena_auth_core::{SmtpConfig, SmtpEmailProvider};

// Re-export entity traits
pub use athena_auth_core::entity::{
    AuthAccount, AuthInvitation, AuthMember, AuthOrganization, AuthPasskey, AuthSession,
    AuthTwoFactor, AuthUser, AuthVerification, MemberUserView,
};

// Re-export types under `types` module for backwards compatibility
pub mod types {
    pub use athena_auth_core::{
        Account, AdminAuditLog, AthenaClient, AuthRequest, AuthResponse, CreateAccount,
        CreateAdminAuditLog, CreateAthenaClient, CreateEmailSendFailure, CreateEmailTemplate,
        CreateInvitation, CreateMember, CreateOrganization, CreatePasskey, CreateSentEmail,
        CreateSession, CreateSessionIpProfileRecord, CreateUser, CreateVerification,
        EmailEventType, EmailSendFailure, EmailTemplate, HttpMethod, Invitation, InvitationStatus,
        IpProfileRecord, ListAdminAuditLogsParams, ListEmailEventTypesParams,
        ListEmailSendFailuresParams, ListEmailTemplatesParams, ListSentEmailsParams, Passkey,
        SentEmail, Session, SessionCreateOptions, SessionIpProfileRecord, TwoFactor,
        UpdateEmailSendFailure, UpdateEmailTemplate, UpdateOrganization, UpdatePasskey,
        UpdateSentEmail, UpdateUser, UpdateUserRequest, UpdateUserResponse, UpsertIpProfileRecord,
        User, Verification,
    };
}

// Re-export adapters
pub mod adapters {
    pub use athena_auth_core::{
        AccountOps, CacheAdapter, DatabaseAdapter, InvitationOps, MemberOps, MemoryAccount,
        MemoryCacheAdapter, MemoryDatabaseAdapter, MemoryInvitation, MemoryMember,
        MemoryOrganization, MemoryPasskey, MemorySession, MemoryUser, MemoryVerification,
        OrganizationOps, PasskeyOps, SessionOps, UserOps, VerificationOps,
    };

    #[cfg(feature = "sqlx-postgres")]
    pub use athena_auth_core::adapters::database::sqlx_adapter::{
        PoolConfig, PoolStats, SqlxAdapter, SqlxEntity,
    };
}

// Re-export plugins
pub mod plugins {
    pub use athena_auth_api::plugins::*;
    pub use athena_auth_api::*;
}

// Re-export the main AthenaAuth struct
pub use core::{AthenaAuth, AuthBuilder, TypedAuthBuilder};

#[cfg(feature = "axum")]
pub use handlers::axum::{
    AxumIntegration, CurrentSession, OptionalSession, dispatch_auth_axum_request,
};

#[cfg(test)]
#[path = "tests/response_shape_tests.rs"]
mod response_shape_tests;

#[cfg(test)]
#[path = "tests/route_collision_precedence_tests.rs"]
mod route_collision_precedence_tests;

#[cfg(test)]
#[path = "tests/trace_id_correlation_tests.rs"]
mod trace_id_correlation_tests;

#[cfg(test)]
#[path = "__tests__/lib.rs"]
mod tests;
