#![allow(unused_imports, dead_code)]

pub use pgmold::diff::{compute_diff, planner::plan_migration, MigrationOp};
pub use pgmold::drift::detect_drift;
pub use pgmold::dump::generate_dump;
pub use pgmold::expand_contract::generate_version_schema_ops;
pub use pgmold::lint::{has_errors, lint_migration_plan, LintOptions};
pub use pgmold::model::{ColumnMapping, PartitionBound, PartitionStrategy, Schema, VersionView};
pub use pgmold::parser::{load_schema_sources, parse_sql_string};
pub use pgmold::pg::connection::PgConnection;
pub use pgmold::pg::introspect::introspect_schema;
pub use pgmold::pg::sqlgen::generate_sql;
pub use serde_json;
pub use sqlx::Executor;
pub use std::collections::BTreeMap;
pub use std::io::Write;
pub use tempfile;
pub use tempfile::NamedTempFile;
pub use testcontainers::runners::AsyncRunner;
pub use testcontainers::ContainerAsync;
pub use testcontainers::ImageExt;
pub use testcontainers_modules::postgres::Postgres;

pub fn write_sql_temp_file(sql: &str) -> NamedTempFile {
    let mut file = tempfile::Builder::new().suffix(".sql").tempfile().unwrap();
    writeln!(file, "{sql}").unwrap();
    file
}

#[allow(deprecated)]
pub async fn setup_postgres() -> (ContainerAsync<Postgres>, String) {
    let pg = Postgres::default();
    let container = match std::env::var("PGMOLD_TEST_PG_VERSION") {
        Ok(version) => pg.with_tag(version).start().await.unwrap(),
        Err(_) => pg.start().await.unwrap(),
    };
    let port = container.get_host_port_ipv4(5432).await.unwrap();
    let url = format!("postgres://postgres:postgres@localhost:{port}/postgres");
    (container, url)
}
