use crate::ui;
use anyhow::{Context, Result};
use colored::Colorize;
use dialoguer::Password;
use syntarq_core::identity::{ServiceType, SyntarqIdentity};
pub async fn run() -> Result<()> {
ui::header("🔐 Initializing Syntarq Vault");
let password: String = Password::new()
.with_prompt("Master Password")
.with_confirmation("Confirm Password", "Passwords don't match")
.interact()
.context("Failed to read password")?;
if password.len() < 10 {
ui::error("Password must be at least 10 characters");
anyhow::bail!("Weak password");
}
if !password.chars().any(|c| c.is_numeric()) {
ui::error("Password must contain at least one number");
anyhow::bail!("Weak password");
}
if !password.chars().any(|c| c.is_alphabetic()) {
ui::error("Password must contain at least one letter");
anyhow::bail!("Weak password");
}
ui::info("Creating vault...");
let (identity, password_hash) =
SyntarqIdentity::create(&password).context("Failed to create identity")?;
ui::separator();
ui::success("Vault initialized successfully!");
ui::section("Identity Information");
ui::kv_pair("Identity ID", &identity.id().to_string());
ui::section("Password Hash");
ui::dimmed(&format!("Hash: {}...", &password_hash[..50]));
ui::section("Service Keys");
for service_type in ServiceType::all() {
let _service_key = identity
.derive_service_key(*service_type)
.context("Failed to derive service key")?;
ui::info(&format!(
" {} - Key derived successfully",
service_type.to_string().yellow()
));
}
ui::separator();
ui::info("💡 Use 'syntarq test-crypto' to test cryptographic functions");
Ok(())
}