{% extends "layout.njk" %}

{% import "macros.njk" as macros %}

{% block main %}

// #[cfg(feature = "proto")]
pub mod proto_types_parsers {
    use yellowstone_vixen_core::proto_helper_traits;
    proto_helper_traits!();
    use crate::proto_def;

    {% for typeHelper in protoTypesHelpers %}
        use crate::types::{{ typeHelper.name | pascalCase }};
        impl IntoProto<proto_def::{{ typeHelper.name | pascalCase }}> for {{ typeHelper.name | pascalCase }} {
            fn into_proto(self) -> proto_def::{{ typeHelper.name | pascalCase }} {
                proto_def::{{ typeHelper.name | pascalCase }} {
                    {% for field in typeHelper.fields %}
                        {{ field.name }}: {{ field.transform }},
                    {% endfor %}
                }
            }
        }   
    {% endfor %}

    {% for typeHelper in protoTypesHelpersEnums %}
        use crate::types::{{ typeHelper.name | pascalCase }};
        use proto_def::{{ typeHelper.name | snakeCase }};
        impl IntoProto<proto_def::{{ typeHelper.name | pascalCase }}> for {{ typeHelper.name | pascalCase }} {
            fn into_proto(self) -> proto_def::{{ typeHelper.name | pascalCase }} {
                let variant = match self {
                {% for variant in typeHelper.variants %}
                    {{ typeHelper.name | pascalCase }}::{{ variant.name | pascalCase}} {{ variant.variant_fields }} => {{ typeHelper.name | snakeCase }}::Variant::{{ variant.name | pascalCase}}(proto_def::{{ typeHelper.name | pascalCase }}{{ normalizeAcronyms(variant.name | pascalCase) }} { {{ variant.fields_transform }} }),
                {% endfor %}
                };

                proto_def::{{ typeHelper.name | pascalCase }} {
                   variant: Some(variant),
                }    
            }
        }   
    {% endfor %}
}

{% endblock %}