{% from 'macros/common_macros.lua.j2' import boolean, string_table %}

{% macro forward_options(options) -%}
{dnssec={{ boolean(options.dnssec) }},auth={{ boolean(options.authoritative) }}}
{%- endmacro %}

{% macro forward_server(server) -%}
{%- if server.address is defined and server.address-%}
{%- for addr in server.address -%}
{'{{ addr }}',
{%- if server.transport == 'tls' -%}
tls=true,
{%- else -%}
tls=false,
{%- endif -%}
{%- if server.hostname -%}
hostname='{{ server.hostname }}',
{%- endif -%}
{%- if server.pin_sha256 -%}
pin_sha256={{ string_table(server.pin_sha256) }},
{%- endif -%}
{%- if server.ca_file -%}
ca_file='{{ server.ca_file }}',
{%- endif -%}
},
{%- endfor -%}
{% else %}
{'{{ server }}'},
{%- endif -%}
{%- endmacro %}

{% macro forward_servers(servers) -%}
{
{%- for server in servers -%}
{{ forward_server(server) }}
{%- endfor -%}
}
{%- endmacro %}

{% macro policy_rule_forward_add(subtree,options,servers) -%}
policy.rule_forward_add('{{ subtree }}',{{ forward_options(options) }},{{ forward_servers(servers) }})
{%- endmacro %}
