use crate::logging::init::init_logging;
use crate::logging::ledger::ensure_ledger_key_exists;
use std::fs;
use std::path::Path;
pub fn init_project() -> Result<String, Box<dyn std::error::Error>> {
init_logging();
ensure_ledger_key_exists();
fs::create_dir_all("contracts")?;
if !Path::new(".env").exists() {
fs::write(".env","#.env")?;
}
let profile_content = r#"# Pipe Audit profile.toml example
# provider can be: "local", "s3", "azure", "gcs"
name = "example-profile"
provider = "local"
# For s3/azure/gcs, add provider-specific fields (endpoint, region, connection_string, service_account_json, etc.)
"#;
if !Path::new("profile.toml").exists() {
fs::write("profile.toml", profile_content)?;
}
let contract_content = r#"# contracts/example.toml
[contract]
name = "example-contract"
version = "0.1.0"
[source]
type = "local"
location = "data/example.csv"
[file.validation]
# row_count.min = 1
# completeness.min_ratio = 0.95
[[columns]]
name = "id"
[[columns.validation]]
type = { dtype = "i64" }
[[columns.validation]]
unique = true
"#;
let contract_path = Path::new("contracts/example.toml");
if !contract_path.exists() {
fs::write(contract_path, contract_content)?;
}
Ok("Initialized logs/, contracts/, profile.toml, and example contract".into())
}