use crate::prelude::*;

#[derive(Serialize)]
pub struct Config {
	password_hash: String,
	password_salt: String,
	port: u16,
}

pub fn configure() {
	let port = utils::prompt("Port: ").unwrap();

	let password = utils::read_matching_passwords().unwrap();
	let (password_hash, password_salt) = utils::hash_password(&password);

	let config = Config {
		password_hash,
		password_salt,
		port,
	};

	let out_path = utils::get_config_file_path("server.toml").unwrap();
	let data = toml::to_string_pretty(&config).unwrap();

	std::fs::write(&out_path, data).unwrap();
	println!("\nWrote config file to {}", out_path.display());
}
