{#- -*- mode: sgml; tab-width: 2; indent-tabs-mode: nil -*-
 #
 # SPDX-License-Identifier: MIT
-#}
{%- import('macros/printElementId.xml.jinja2') as peid %}
{%- import('macros/printAdminData.xml.jinja2') as pad %}
{%- import('macros/printDescription.xml.jinja2') as pd %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}

{%- macro printDiagVariable(diag_var) -%}
<DIAG-VARIABLE {{-peid.printElementIdAttribs(diag_var)}}
               {{-make_bool_xml_attrib("IS-READ-BEFORE-WRITE", diag_var.is_read_before_write_raw}}>
  {{ peid.printElementIdSubtags(diag_variable)|indent(2) }}
  {%- if diag_variable.admin_data is not none %}
  {{ pad.printAdminData(diag_variable.admin_data)|indent(2) }}
  {%- endif %}
  <VARIABLE-GROUP-REF ID-REF="{{ diag_var.ref_id }}" />
  {%- if diag_variable.sw_variables %}
   <SW-VARIABLES>
    {%- for sw_var in diag_variable.sw_variables %}
    <SW-VARIABLE {{-peid.printElementIdAttribs(sw_var)}} {{- make_xml_attrib("OID", sw_var.oid) }}>
      {{ peid.printElementIdSubtags(sw_var)|indent(6) }}
      {%- if sw_var.origin is not none %}
      <ORIGIN>{{ sw_var.origin }}</ORIGIN>
      {%- endif %}
    </SW-VARIABLE>
    {%- endfor %}
  </SW-VARIABLES>
  {%- endif %}
  {%- if diag_variable.comm_relations %}
  <COMM-RELATIONS>
    {%- for comm_relation in diag_variable.comm_relations %}
    <COMM-RELATION>
      {{ pd.printDescription(comm_relation.description) }}
      <RELATION-TYPE>{{comm_relation.relation_type}}</RELATION-TYPE>
      {%- if comm_relation.diag_comm_ref is not none %}
      <DIAG-COMM-REF ID-REF="{{comm_relation.diag_comm_ref.ref_id}}" />
      {%- endif %}
      {%- if comm_relation.diag_comm_snref is not none %}
      <DIAG-COMM-SNREF SHORT-NAME="{{comm_relation.diag_comm_snref}}" />
      {%- endif %}
      {%- if comm_relation.in_param_if_ref is not none %}
      <IN-PARAM-IF-REF ID-REF="{{comm_relation.in_param_if_ref.ref_id}}" />
      {%- endif %}
      {%- if comm_relation.in_param_if_snref is not none %}
      <IN-PARAM-IF-SNREF SHORT-NAME="{{comm_relation.in_param_if_snref}}" />
      {%- endif %}
      {%- if comm_relation.out_param_if_ref is not none %}
      <OUT-PARAM-IF-REF ID-REF="{{comm_relation.out_param_if_ref.ref_id}}" />
      {%- endif %}
      {%- if comm_relation.out_param_if_snref is not none %}
      <OUT-PARAM-IF-SNREF SHORT-NAME="{{comm_relation.out_param_if_snref}}" />
      {%- endif %}
      {%- if comm_relation.value_type_raw is not none %}
      <VALUE-TYPE>{{comm_relation.value_type_raw.value}}</VALUE-TYPE>
      {%- endif %}
    <COMM-RELATION>
    {%- endfor %}
  </COMM-RELATIONS>
  {%- endif %}
  {%- if diag_variable.table_snref is not none %}
  <SNREF-TO-TABLE-ROW>
    <TABLE-SNREF SHORT-NAME="{{diag_variable.table_snref}}" />
    <TABLE-ROW-SNREF SHORT-NAME="{{diag_variable.table_row_snref}}" />
  </SNREF-TO-TABLE-ROW>
  {%- endif %}
  {{- psd.printSpecialDataGroups(ddds.sdgs)|indent(2, first=True) }}
</DIAG-VARIABLE>
{%- endmacro -%}

{%- macro printVariableGroup(var_group) -%}
<VARIABLE-GROUP {{-peid.printElementIdAttribs(var_group)}}>
  {{ peid.printElementIdSubtags(diag_variable)|indent(2) }}
</VARIABLE-GROUP>
{%- endmacro -%}
