{# ei-scanner jinja template, for `` #}
#![allow(unused_imports, unused_parens, clippy::useless_conversion, clippy::double_parens, clippy::match_single_binding, clippy::unused_unit)]

// GENERATED FILE

{% for interface in interfaces %}
pub(crate) mod {{interface.plainname}} {
    use crate::wire;

    {% for enum in interface.enums %}
    /// {{enum.description.summary|capitalize}}.
    ///
    /** {{enum.description.text|ei_escape_names}} */
    #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
    pub enum {{enum.camel_name}} {
        {% for entry in enum.entries %}
        /// {{entry.summary|capitalize}}.
        {{entry.name|camel}} = {{entry.value}},
        {% endfor %}
    }

    impl From<{{enum.camel_name}}> for u32 {
        fn from(value: {{enum.camel_name}}) -> u32 {
            value as u32
        }
    }

    impl wire::OwnedArg for {{enum.camel_name}} {
        fn parse(buf: &mut wire::ByteStream) -> Result<Self, wire::ParseError> {
            match u32::parse(buf)? {
            {% for entry in enum.entries %}
                {{entry.value}} => Ok(Self::{{entry.name|camel}}),
            {% endfor %}
        variant => Err(wire::ParseError::InvalidVariant("{{enum.camel_name}}", variant)),
            }
        }

        fn as_arg(&self) -> wire::Arg<'_> {
            wire::Arg::Uint32(*self as u32)
        }

        fn enum_name(&self) -> Option<(&'static str, &'static str)> {
            Some(("{{enum.name}}", match self {
                {% for entry in enum.entries %}
                Self::{{entry.name|camel}} => "{{entry.name}}",
                {% endfor %}
            }
            ))
        }
    }
    {% endfor %}
}

{% endfor %}
