<template name="cisco_ios_vrfs" results="per_template">
<doc>
Template to parse Cisco IOS VRF configuration and normalize it to a flat list
of VRF dictionaries.

This template requires output of 'show running-config | section vrf'.

Returns normalized list of dictionaries, each dictionary has these keys:

- `name` - VRF name string
- `instance_type` - always `vrf`
- `description` - VRF description string or `null` when not configured
- `rd` - route distinguisher string or `null` when not configured
- `interfaces` - list of interface names assigned to the VRF
- `address_families` - dictionary containing `ipv4` and `ipv6`; each family
  contains `rt_import`, `rt_export`, `route_policy_import`, and
  `route_policy_export`

Example normalized output (YAML):

```yaml
- name: CUSTOMER_A
  instance_type: vrf
  description: Customer A VRF
  rd: 65000:100
  interfaces:
  - GigabitEthernet0/0.100
  address_families:
    ipv4:
      rt_import:
      - 65000:100
      rt_export:
      - 65000:100
      route_policy_import: IMPORT-CUSTOMER-A
      route_policy_export: EXPORT-CUSTOMER-A
    ipv6:
      rt_import: []
      rt_export: []
      route_policy_import: null
      route_policy_export: null
```

</doc>

<input>
commands = [
    "show running-config | section vrf"
]
platform = [
    "cisco_ios", # Netmiko and Scrapli
    "ios", # NAPALM
]
</input>

<macro>
def transform_vrfs_to_records(data):
    from ttp_templates.utils.cisco_ios_process_show_running_config_pipe_section_vrf import transform_vrfs_config

    return transform_vrfs_config(data)
</macro>

<group name="vrfs**.{{ name }}**">
ip vrf {{ name | _start_ }}
 description {{ description | re(".+") }}
 rd {{ rd }}
 route-target export {{ rt_export | to_list | joinmatches }}
 route-target import {{ rt_import | to_list | joinmatches }}
 route-target both {{ rt_both | to_list | joinmatches }}
 export map {{ route_policy_export }}
 import map {{ route_policy_import }}
!{{ _end_ }}
</group>

<group name="vrfs**.{{ name }}**">
vrf definition {{ name | _start_ }}
 description {{ description | re(".+") }}
 rd {{ rd }}
 route-target export {{ rt_export | to_list | joinmatches }}
 route-target import {{ rt_import | to_list | joinmatches }}
 route-target both {{ rt_both | to_list | joinmatches }}
 export map {{ route_policy_export }}
 import map {{ route_policy_import }}

 <group name="address_families**.{{ afi }}**">
 address-family {{ afi | re(".+") | _start_ }}
  route-target export {{ rt_export | to_list | joinmatches }}
  route-target import {{ rt_import | to_list | joinmatches }}
  route-target both {{ rt_both | to_list | joinmatches }}
  export map {{ route_policy_export }}
  import map {{ route_policy_import }}
 exit-address-family {{ _end_ }}
 </group>

!{{ _end_ }}
</group>

<group name="interfaces*">
interface {{ name | _start_ }}
 ip vrf forwarding {{ vrf }}
 vrf forwarding {{ vrf }}
!{{ _end_ }}
</group>

<output macro="transform_vrfs_to_records"/>

</template>
