//! Account domain logic — account deletion with KT tombstone.

use std::sync::{Arc, Mutex};

use quicproquo_kt::MerkleLog;

use crate::storage::Store;

use super::types::DomainError;

/// Domain service for account lifecycle operations.
pub struct AccountService {
    pub store: Arc<dyn Store>,
    pub kt_log: Arc<Mutex<MerkleLog>>,
}

impl AccountService {
    pub fn delete_account(&self, caller_identity_key: &[u8]) -> Result<(), DomainError> {
        self.store.delete_account(caller_identity_key)?;

        // Append a KT tombstone entry so the deletion is auditable.
        if let Ok(mut log) = self.kt_log.lock() {
            log.append("__tombstone__", caller_identity_key);
        }

        Ok(())
    }
}
