use sqlx::postgres::{PgPool, PgPoolOptions};

use crate::relations::{Relation, RelationType};

pub static CONN_STRING: &str = "postgres://pgtui_tests:1234@localhost:5437/pgtui_tests";

pub async fn test_db() -> PgPool {
    PgPoolOptions::new()
        .max_connections(1)
        .connect(CONN_STRING)
        .await
        .expect("Unable to connect to the database")
}

pub async fn make_relation(name: String, relation_type: RelationType) -> Relation {
    Relation {
        name,
        relation_type,
        owner: "pgtui_tests".to_string(),
        schema: "public".to_string(),
        data_definition: None,
    }
}

pub async fn make_blog_table_relation() -> Relation {
    Relation {
        name: "blog".to_string(),
        relation_type: RelationType::Table,
        owner: "pgtui_tests".to_string(),
        schema: "public".to_string(),
        data_definition: None,
    }
}

mod tests {
    use super::*;

    #[tokio::test]
    async fn test_connection() {
        let _ = test_db().await;
        assert_eq!(1, 1);
    }
}
