resource "grafana_oncall_escalation_chain" "this" {
  name    = var.name
  team_id = var.team_id
}

resource "grafana_oncall_escalation" "steps" {
  # ключ = строковый индекс; порядок шагов фиксирован через position
  for_each = { for idx, step in var.steps : tostring(idx) => step }

  escalation_chain_id              = grafana_oncall_escalation_chain.this.id
  type                             = each.value.type
  position                         = tonumber(each.key)
  duration                         = each.value.duration_seconds
  persons_to_notify                = each.value.persons_to_notify
  persons_to_notify_next_each_time = each.value.persons_to_notify_next_each_time
  notify_on_call_from_schedule     = each.value.notify_on_call_from_schedule
  group_to_notify                  = each.value.group_to_notify
  action_to_trigger                = each.value.action_to_trigger
  notify_to_team_members           = each.value.notify_to_team_members
  important                        = each.value.important
}
