{#
    Warn people opening the resulting file it is generated using this template
    and the accompanying script.
-#}
////
    Do not modify this file directly, it is automatically generated by combining
    the Python script `docs/utils/schema-objs.py` and the template
    `docs/utils/schema-objs.adoc.j2`. Please refer to the Python script comments
    to discover how it is used.
////
{#
    Macro to represent the type of an object attribute
#}
{%- macro represent_type(data_type) -%}
{%- if data_type.__class__.__name__ == 'SchemaContainerList' -%}
{symbol-seq}{nbsp}{{ represent_type(data_type.content) }}
{%- elif data_type.__class__.__name__ == 'SchemaReference' -%}
{symbol-ref}{nbsp}{{ represent_type(data_type.obj) }}{% if data_type.prop is not none %}.{{data_type.prop}}{% endif %}
{%- elif data_type.__class__.__name__ == 'SchemaBackReference' -%}
{{ represent_type(data_type.obj) }}{% if data_type.prop is not none %}.{{data_type.prop}}{% endif %}
{%- elif data_type.__class__.__name__ == 'SchemaObject' -%}
xref:#obj-{{ data_type.name|lower() }}[{symbol-obj}{nbsp}{{ data_type.name }}]
{%- elif 'SchemaDefinedType' in data_type|bases -%}
xref:#deftype-{{ data_type.name[deftype_prefix|length:]|lower() }}[{symbol-deftype}{nbsp}~{{ data_type.name[deftype_prefix|length:] }}]
{%- else -%}
{{ data_type }}
{%- endif -%}
{%- endmacro -%}

{%- macro represent_automatic_prop_name(prop) -%}
{%- if prop.type.__class__.__name__ == 'SchemaBackReference' -%}
{symbol-backref}
{%- elif prop.computed -%}
{symbol-computed}
{%- endif -%}
{nbsp}{{ prop.name }}
{%- endmacro -%}
{#
    Macro to render obj attributes table
#}
{%- macro obj_attributes(obj) -%}
.Properties
[cols="{tbl-obj-props-cols-specs}"]
|===
|Property|Description|Type|Required
{% for prop in obj.properties if not prop.type.__class__.__name__ == 'SchemaBackReference' and not prop.computed %}
|{{ prop.name }}{% if prop.key is true %}{nbsp}{symbol-key}{% endif %}
|{{ prop.description }}
{% if prop.default is not none %}
{%- if prop.default is mapping %}
*Default value:*

[source,yaml]
----
{{prop.default|toyaml}}
----
{%- else %}
*Default value:* `{{prop.default}}`
{%- endif %}
{%- endif %}
|{{ represent_type(prop.type) }}
|{% if prop.required is false %}[.grey]#-#{% else %}[.green]#icon:check[]#{% endif %}
{% endfor -%}
|===
{%- endmacro -%}
{#
    Macro to render obj backrefs table
#}
{%- macro obj_backrefs(obj) %}

.Automatic properties
[cols="{tbl-obj-backrefs-cols-specs}"]
|===
|Property|Description|Type
{% for prop in obj.properties if prop.type.__class__.__name__ == 'SchemaBackReference' or prop.computed %}
|{{ represent_automatic_prop_name(prop) }}
|{{ prop.description }}
|{{ represent_type(prop.type) }}
{% endfor -%}
|===
{%- endmacro -%}
:tbl-obj-props-cols-specs: 2m,6a,4,^.^1
:tbl-obj-backrefs-cols-specs: 4m,6a,4

[#obj-root]
== Database Root

Library class type: `{{object_prefix}}`

{{ obj_attributes(schema.content) }}

[#objects]
== Objects
{#-
    Iterate over the various objects sorted in lexicographical order.
-#}
{% for obj in schema.objects.values()|sort(attribute='name') %}

[#obj-{{ obj.name|lower() }}]
=== {{ obj.name }}

Library class type: `{{object_prefix}}{{ obj.name }}`
{% if obj.description is not none %}
{{ obj.description }}
{% endif %}
{{ obj_attributes(obj) }}
{%- if obj.has_backref -%}
{{ obj_backrefs(obj) }}
{%- endif -%}
{%- endfor %}
