use bcrypt::{hash, DEFAULT_COST};
use crate::core::security::legacy_adapter::LegacyAuthAdapter;
use crate::core::security::sandi_an::SandiAN;
fn resolve_app_key() -> String {
std::env::var("APP_KEY")
.or_else(|_| std::env::var("JWT_SECRET"))
.unwrap_or_else(|_| "pakem-app-secret-pepper-key-2026".to_string())
}
pub fn make(password: &str) -> String {
let app_key = resolve_app_key();
let sandi = SandiAN::encode_with_key(password, &app_key);
let pepper = LegacyAuthAdapter::compute_pepper(&sandi, &app_key);
hash(pepper, DEFAULT_COST).expect("Gagal melakukan hashing password Tri-Layer Pakem")
}
pub fn check(password: &str, hashed: &str) -> bool {
let app_key = resolve_app_key();
let (is_valid, _) = LegacyAuthAdapter::verify_and_check_migration(password, hashed, Some(&app_key));
is_valid
}
pub fn check_with_migration(password: &str, hashed: &str) -> (bool, bool) {
let app_key = resolve_app_key();
LegacyAuthAdapter::verify_and_check_migration(password, hashed, Some(&app_key))
}