use super::exec::execute_command_internal;
use super::super::error::BtrfsError;
use super::super::path_utils::path_to_str;
use std::path::{Path, PathBuf};

pub fn find_mountpoint(device: &Path) -> Result<PathBuf, BtrfsError> {
    let device_str = path_to_str(device)?;
    
    let result = execute_command_internal("findmnt", &["-n", "-o", "TARGET", device_str])?;
    
    let mount_point = result.stdout.trim().to_string();
    if mount_point.is_empty() {
        return Err(BtrfsError::NotMounted(format!(
            "Device {} is not mounted (findmnt returned empty output)",
            device_str
        )));
    }
    
    Ok(PathBuf::from(mount_point))
}

