use std::time::Duration;

/// Supported database kinds.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DatabaseKind {
    /// SQLite.
    Sqlite,
    /// PostgreSQL.
    Postgres,
    /// MySQL.
    Mysql,
}

/// Database connection pool configuration.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DatabaseConfig {
    /// Database kind.
    pub kind: DatabaseKind,
    /// Database URL.
    pub url: String,
    /// Maximum connections.
    pub max_connections: u32,
    /// Connection timeout.
    pub connect_timeout: Duration,
}

impl DatabaseConfig {
    /// Creates a SQLite database configuration.
    pub fn sqlite(url: impl Into<String>) -> Self {
        Self {
            kind: DatabaseKind::Sqlite,
            url: url.into(),
            max_connections: 5,
            connect_timeout: Duration::from_secs(5),
        }
    }

    /// Creates a PostgreSQL database configuration.
    pub fn postgres(url: impl Into<String>) -> Self {
        Self {
            kind: DatabaseKind::Postgres,
            url: url.into(),
            max_connections: 5,
            connect_timeout: Duration::from_secs(5),
        }
    }

    /// Creates a MySQL database configuration.
    pub fn mysql(url: impl Into<String>) -> Self {
        Self {
            kind: DatabaseKind::Mysql,
            url: url.into(),
            max_connections: 5,
            connect_timeout: Duration::from_secs(5),
        }
    }
}

impl Default for DatabaseConfig {
    fn default() -> Self {
        Self::sqlite("sqlite::memory:")
    }
}
