use crate::core::config::DATABASE_SCHEMA;
use once_cell::sync::Lazy;

pub static SCHEMA_PREFIX: Lazy<String> = Lazy::new(|| {
    let schema = DATABASE_SCHEMA.as_str();
    if schema == "public" {
        String::new()
    } else {
        format!("{}.", schema)
    }
});

pub fn table_name(table: &str) -> String {
    let prefix = SCHEMA_PREFIX.as_str();
    if prefix.is_empty() {
        table.to_string()
    } else {
        format!("{}{}", prefix, table)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_table_name_public() {
        assert_eq!(table_name("videos"), "videos");
    }
}
