locals {
  # Group folders by whether they should keep manual changes or be protected from destruction
  folders_ignore_only = {
    for group in var.groups : group.dashboard_alert_group_name => group
    if lookup(group, "keep_manual_changes", false) && !lookup(group, "prevent_destroy_on_recreate", false)
  }

  folders_protect_only = {
    for group in var.groups : group.dashboard_alert_group_name => group
    if !lookup(group, "keep_manual_changes", false) && lookup(group, "prevent_destroy_on_recreate", false)
  }

  folders_ignore_and_protect = {
    for group in var.groups : group.dashboard_alert_group_name => group
    if lookup(group, "keep_manual_changes", false) && lookup(group, "prevent_destroy_on_recreate", false)
  }

  folders_standard = {
    for group in var.groups : group.dashboard_alert_group_name => group
    if !lookup(group, "keep_manual_changes", false) && !lookup(group, "prevent_destroy_on_recreate", false)
  }
}
