use serde::Serialize;
use hwpforge_smithy_hwpx::{FieldInfo, HwpxFiller};
use crate::output::{read_file_bytes, ToolErrorInfo};
#[derive(Debug, Serialize)]
pub struct FieldsData {
pub fields: Vec<FieldInfo>,
pub fillable_count: usize,
}
pub fn run_fields(file_path: &str) -> Result<FieldsData, ToolErrorInfo> {
let bytes = read_file_bytes(file_path)?;
let fields = HwpxFiller::list_fields(&bytes).map_err(|e| {
ToolErrorInfo::new(
"DECODE_ERROR",
format!("HWPX decode failed: {e}"),
"Check that the file is valid HWPX. For .hwp files, convert with hwpforge_convert first.",
)
})?;
let fillable_count = fields.iter().filter(|f| f.fillable).count();
Ok(FieldsData { fields, fillable_count })
}