[# Snapshot Control V1 Template #]
[# Generates the snapshot control logic with retention patterns #]

[# Compute v0_name from name (remove any suffix and add _v0) #]
[% set base_name = name.replace('_v0', '').replace('_v1', '') %]
[% set control_v0_name = base_name ~ '_v0' -%]

{{ config(
    materialized='view',
    tags=['snapshot_control', 'control']
) }}

{%- set yaml_metadata -%}
control_snap_v0: [[ control_v0_name ]]
log_logic:
[% for pattern in logic_patterns %]
    [[ pattern.component ]]:
[% if pattern.forever %]
        forever: true
[% else %]
        duration: [[ pattern.duration ]]
        unit: '[[ pattern.unit ]]'
[% endif %]
[% endfor %]
{%- endset -%}

{{ datavault4dbt.control_snap_v1(yaml_metadata=yaml_metadata) }}
