// pub mod token_manager;
// pub mod crypto;
// pub mod webauthn;
// pub mod storage;
// pub mod http_interceptor;

// pub use token_manager::*;
// pub use crypto::*;
// pub use webauthn::*;
// pub use storage::*;
// pub use http_interceptor::*;

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AuthToken {
    pub access_token: String,
    pub refresh_token: String,
    pub expires_at: DateTime<Utc>,
    pub token_type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoginCredentials {
    pub email: String,
    pub password: String,
    pub remember_me: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MfaCredentials {
    pub token: String,
    pub code: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    pub id: Uuid,
    pub email: String,
    pub name: String,
    pub mfa_enabled: bool,
    pub device_trust_enabled: bool,
    pub last_login: Option<DateTime<Utc>>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AuthState {
    pub user: Option<User>,
    pub token: Option<AuthToken>,
    pub is_authenticated: bool,
    pub is_loading: bool,
    pub mfa_required: bool,
    pub trusted_device: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthError {
    pub message: String,
    pub code: Option<String>,
    pub field: Option<String>,
}

impl std::fmt::Display for AuthError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for AuthError {}

pub type AuthResult<T> = Result<T, AuthError>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrustedDevice {
    pub id: Uuid,
    pub name: String,
    pub device_fingerprint: String,
    pub user_agent: String,
    pub ip_address: String,
    pub created_at: DateTime<Utc>,
    pub last_used: DateTime<Utc>,
    pub is_current: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SsoProvider {
    pub id: String,
    pub name: String,
    pub provider_type: SsoProviderType,
    pub icon: String,
    pub enabled: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[allow(clippy::upper_case_acronyms)]
pub enum SsoProviderType {
    OAuth2,
    SAML,
    OIDC,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PasswordResetRequest {
    pub email: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PasswordResetConfirm {
    pub token: String,
    pub new_password: String,
    pub confirm_password: String,
}
