<template name="fortinet_bgp_neighbors" results="per_template">
<doc>
Parse Fortinet FortiOS `get router info bgp neighbors` for the
`bgp_neighbors` getter.

Returns one normalized record per VRF and neighbor address; FortiOS lists IPv4
and IPv6 neighbors together, under a `VRF N neighbor table:` heading per VRF.
VRF 0 is the default (`vrf` is `null`); any other is its number as a string.
Session state, peering type, remote and local ASN, router ID, local address,
BGP uptime and per address family prefix counts are collected. Hold time and
keepalive are read only for an established session: FortiOS prints the
configured timers for the others. Address families come from the
`For address family` section headers, rather than capability lines. Values not
reported are `null` or empty lists. Tested with FortiOS 7.4 output.
</doc>

<input>
commands = [
    "get router info bgp neighbors"
]
platform = [
    "fortinet", # netmiko
    "fortinet_fortios", # scrapli community
    "fortios", # NAPALM community driver
]
</input>

<macro>
def transform(payload):
    from ttp_templates.utils.fortinet_process_get_router_info_bgp_neighbors import transform_bgp_neighbors

    return transform_bgp_neighbors(payload)
</macro>

<group name="vrfs*">
VRF {{ vrf | _start_ }} neighbor table:
<group name="neighbors*">
BGP neighbor is {{ remote_address | _start_ }}, remote AS {{ remote_as | to_int }}, local AS {{ local_as | to_int }}, {{ peering_type }} link
  BGP version {{ ignore }}, remote router ID {{ router_id }}
  BGP state = {{ bgp_state | ORPHRASE }}
  Last read {{ ignore }}, hold time is {{ hold_time | to_int }}, keepalive interval is {{ keepalive | to_int }} seconds
Local host: {{ local_address }}, Local port: {{ ignore }}
 <group name="families*">
 For address family: {{ afi_name | ORPHRASE | _start_ }}
  {{ prefixes_received | to_int }} accepted prefixes, {{ ignore("ORPHRASE") }}
  {{ prefixes_sent | to_int }} announced prefixes
 </group>
</group>
</group>

<output macro="transform"/>
</template>
