use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize};

fn deserialize_metamodule<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
    D: Deserializer<'de>,
{
    #[derive(Deserialize)]
    #[serde(untagged)]
    enum MetamoduleValue {
        Bool(bool),
        Int(i64),
        String(String),
    }

    let value = MetamoduleValue::deserialize(deserializer)?;
    match value {
        MetamoduleValue::Bool(b) => Ok(b),
        MetamoduleValue::Int(i) => match i {
            0 => Ok(false),
            1 => Ok(true),
            _ => Err(D::Error::custom(format!(
                "Invalid integer value for metamodule: {i}. Expected 0 or 1."
            ))),
        },
        MetamoduleValue::String(s) => match s.as_str() {
            "true" | "1" => Ok(true),
            "false" | "0" => Ok(false),
            _ => Err(D::Error::custom(format!(
                "Invalid string value for metamodule: {s}. Expected 'true', 'false', '0', or '1'."
            ))),
        },
    }
}

/// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public struct 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[allow(non_snake_case)]
pub struct PropSection {
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'id' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub id: String,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'name' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub name: String,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'version' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub version: String,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'versionCode' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub versionCode: i64,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'author' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub author: Option<String>,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'description' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub description: String,
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'updateJson' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub updateJson: Option<String>,
    #[serde(default, deserialize_with = "deserialize_metamodule")]
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public field 'metamodule' in 'PropSection'. Replace with real documentation. (2025-12-30T22:23:21Z)
    pub metamodule: bool,
}

impl PropSection {
    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public function 'get_name'. Replace with real documentation. (2025-12-30T22:23:21Z)
    #[must_use]
    pub fn get_name(&self) -> &str {
        &self.name
    }

    /// AUTO-GENERATED BY Kam/scripts/add_missing_docs.py: placeholder documentation for public function 'get_description'. Replace with real documentation. (2025-12-30T22:23:21Z)

    #[must_use]
    pub fn get_description(&self) -> &str {
        &self.description
    }
}

impl Default for PropSection {
    fn default() -> Self {
        Self {
            id: "example_module_id".to_string(),
            name: "Example Module Name".to_string(),
            version: "1.0.0".to_string(),
            versionCode: 1,
            author: Some("Your Name".to_string()),
            description: "Describe your module here".to_string(),
            updateJson: Some(
                "https://raw.githubusercontent.com/user/repo/branch/update.json".to_string(),
            ),
            metamodule: false,
        }
    }
}
