use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[allow(non_snake_case)]
// 额外包含的文件配置
/// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public struct 'ExtraInclude'. Replace with real documentation. (2025-12-30T22:23:21Z)
pub struct ExtraInclude {
    // 源文件相对路径（相对于项目根目录）
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'source' in 'ExtraInclude'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub source: String,
    // 目标路径（打包进压缩包的相对路径）
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'dest' in 'ExtraInclude'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub dest: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[allow(non_snake_case)]
// 打包/构建配置节
// - source_dir：自定义源代码目录（默认为 "src/{{id}}"，初始化时会展开为实际模块 ID）
// - target_dir：打包输出目录，默认 "dist"
// - output_file：可选的输出文件名（为空时使用 <id>-<versionCode>-<version>.zip）
// - hooks_dir：钩子脚本目录，默认 "hooks"
// - extra_includes：额外包含的文件列表
// - exclude：额外的排除路径列表（支持 glob 模式）。默认包含常见的排除项（如 `.git/`, `target/`, `node_modules/`, 以及临时/临时文件）
// - include：强制包含的路径列表（覆盖 exclude，支持 glob 模式）。默认为空数组（会显式写入生成的 `kam.toml`，方便用户直接修改）
// - respect_gitignore：是否尊重顶层 `.gitignore` 的规则（默认 false），由 `kam.toml` 中 `kam.build.respect_gitignore` 显式控制。
/// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public struct 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
pub struct BuildSection {
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'source_dir' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub source_dir: Option<String>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'target_dir' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub target_dir: Option<String>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'output_file' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub output_file: Option<String>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'hooks_dir' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub hooks_dir: Option<String>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'extra_includes' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub extra_includes: Option<Vec<ExtraInclude>>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'exclude' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub exclude: Option<Vec<String>>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'include' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub include: Option<Vec<String>>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'respect_gitignore' in 'BuildSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub respect_gitignore: Option<bool>,
}

impl Default for BuildSection {
    fn default() -> Self {
        Self {
            source_dir: Some("src/{{id}}".to_string()),
            target_dir: Some("dist".to_string()),
            output_file: Some("{{id}}-{{versionCode}}-{{version}}".to_string()),
            hooks_dir: Some("hooks".to_string()),
            extra_includes: None,
            exclude: Some(vec![
                ".git/".to_string(),
                "target/".to_string(),
                "node_modules/".to_string(),
                ".DS_Store".to_string(),
                "Thumbs.db".to_string(),
                "*.tmp".to_string(),
                "*.log".to_string(),
                "*.bak".to_string(),
                ".kam/".to_string(),
            ]),
            // Visible but empty by default so users see the field and can add entries.
            include: Some(Vec::new()),
            // By default do NOT respect .gitignore; explicit control via kam.toml.
            respect_gitignore: Some(false),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::BuildSection;

    #[test]
    fn default_build_include_is_present_and_empty() {
        let b = BuildSection::default();
        assert!(
            b.include.is_some(),
            "build.include should be present (Some), so it appears in generated kam.toml"
        );
        assert!(
            b.include.as_ref().unwrap().is_empty(),
            "build.include default should be an empty array"
        );
    }

    #[test]
    fn default_build_exclude_contains_common_entries_and_not_gitignore() {
        let b = BuildSection::default();
        let excludes = b.exclude.unwrap_or_default();
        assert!(
            excludes
                .iter()
                .any(|s| s == ".git/" || s == "node_modules/"),
            "default exclude should contain common directories like .git/ or node_modules/"
        );
        assert!(
            !excludes.iter().any(|s| s == ".gitignore"),
            "default exclude must not contain .gitignore"
        );
    }
}
