function firewall::apply_preset() {
  local name="$1"
  local client_ip="$2"
  local preset_file
  preset_file="$(ctx::preset::path "${name}.preset")"

  if [[ ! -f "$preset_file" ]]; then
    log::error "Preset not found: ${name}"
    return 1
  fi

  source "$preset_file"

  if [[ -n "${BLOCK_IPS:-}" ]]; then
    for ip in $BLOCK_IPS; do
      firewall::block_ip "$client_ip" "$ip"
      firewall::save_block "$client_ip" "$client_ip" "$ip"
    done
  fi

  if [[ -n "${BLOCK_SUBNETS:-}" ]]; then
    for subnet in $BLOCK_SUBNETS; do
      firewall::block_subnet "$client_ip" "$subnet"
      firewall::save_block "$client_ip" "$client_ip" "$subnet"
    done
  fi

  if [[ -n "${BLOCK_PORTS:-}" ]]; then
    for entry in $BLOCK_PORTS; do
      local target port proto
      IFS=":" read -r target port proto <<< "$entry"
      proto="${proto:-tcp}"
      firewall::block_port "$client_ip" "$target" "$port" "$proto"
      firewall::save_block "$name" "$client_ip" "$target" "$port" "$proto"
    done
  fi

  log::wg_preset "Applied preset '${name}' to: ${client_ip}"
}