{% macro field(field, indent_level) %}
{% filter indent(indent_level) %}

field {{ field.name }} type {{ field.type }} {
    {% if field.indexing %}
    {% if field.indexing_as_multiline %}
    indexing {
        {% for line in field.indexing_as_multiline %}
        {{ line }}
        {% endfor %}
    }
    {% else %}
    indexing: {{ field.indexing_to_text }}
    {% endif %}
    {% endif %}
    {% if field.index_configurations %}
    {% if field.use_simple_index_syntax %}
    index: {{ field.index_configurations[0] }}
    {% else %}
    index {
        {% for index_config in field.index_configurations %}
        {% if index_config is mapping %}
        {% for key, value in index_config.items() %}
        {% if value is none %}
        {{ key }}
        {% else %}
        {{ key }}: {{ value }}
        {% endif %}
        {% endfor %}
        {% else %}
        {{ index_config }}
        {% endif %}
        {% endfor %}
    }
    {% endif %}
    {% endif %}
    {% if field.ann or field.attribute %}
    attribute {
        {% if field.ann %}
        distance-metric: {{ field.ann.distance_metric }}
        {% endif %}
        {% if field.attribute %}
        {% for attribute in field.attribute %}
        {{ attribute }}
        {% endfor %}
        {% endif %}
    }
    {% endif %}
    {% if field.ann %}
    index {
        hnsw {
            max-links-per-node: {{ field.ann.max_links_per_node }}
            neighbors-to-explore-at-insert: {{ field.ann.neighbors_to_explore_at_insert }}
        }
    }
    {% endif %}
    {% if field.match %}
    match {
        {% for match in field.match %}
        {% if match is string %}
        {{ match }}
        {% else %}
        {{ match.0 }}: {{ match.1 }}
        {% endif %}
        {% endfor %}
    }
    {% endif %}
    {% if field.weight %}
    weight: {{ field.weight }}
    {% endif %}
    {% if field.bolding %}
    bolding: on
    {% endif %}
    {% if field.summary %}
    {% for line in field.summary.as_lines %}
    {{ line }}
    {% endfor %}
    {% endif %}
    {% if field.stemming %}
    stemming: {{ field.stemming }}
    {% endif %}
    {% if field.rank %}
    rank: {{ field.rank }}
    {% endif %}
    {% if field.query_command %}
    {% for qc in field.query_command %}
    query-command: {{ qc }}
    {% endfor %}
    {% endif %}
    {% if field.alias %}
    {% for alias in field.alias %}
    {% if ':' in alias %}
    alias {{ alias.split(':')[0].strip(' ') }}: {{ alias.split(':')[1].strip(' ') }}
    {% else %}
    alias: {{ alias }}
    {% endif %}
    {% endfor %}
    {% endif %}
    {% if field.struct_fields %}
    {% for struct_field in field.struct_fields %}
    struct-field {{ struct_field.name }} {
        {% if struct_field.indexing %}
        {% if struct_field.indexing_as_multiline %}
        indexing {
            {% for line in struct_field.indexing_as_multiline %}
            {{ line }}
            {% endfor %}
        }
        {% else %}
        indexing: {{ struct_field.indexing_to_text }}
        {% endif %}
        {% endif %}
        {% if struct_field.attribute %}
        attribute {
            {% for attribute in struct_field.attribute %}
            {{ attribute }}
            {% endfor %}
        }
        {% endif %}
        {% if struct_field.match %}
        match {
            {% for match in struct_field.match %}
            {% if match is string %}
            {{ match }}
            {% else %}
            {{ match.0 }}: {{ match.1 }}
            {% endif %}
            {% endfor %}
        }
        {% endif %}
        {% if field.query_command %}
        {% for qc in field.query_command %}
        query-command: {{ qc }}
        {% endfor %}
        {% endif %}
        {% if field.alias %}
        {% for alias in field.alias %}
        alias: {{ alias }}
        {% endfor %}
        {% endif %}
        {% if struct_field.summary %}
        summary {% if struct_field.summary.name %}{{struct_field.summary.name}}{% endif %}{% if struct_field.summary.type %} type {{ struct_field.summary.type }} {% endif %}{
            {% for field in struct_field.summary.attributes_as_string_list %}
            {{ field }}
            {% endfor %}
        }
        {% endif %}
        {% if struct_field.rank %}
        rank: {{ struct_field.rank }}
        {% endif %}
    }
    {% endfor %}
    {% endif %}
}{% endfilter %}
{% endmacro %}
