def insecure_client(insecure_single_connection_string):
    return EventStoreDBClient(insecure_single_connection_string)
def client(connection_string):
    return EventStoreDBClient(connection_string)
def secure_client(secure_cluster_connection_string):
    return EventStoreDBClient(secure_cluster_connection_string)
"""Runs a subscription example."""

from eventstore_grpc import EventStoreDBClient, JSONEventData
from eventstore_grpc.options import base_options
import time
import json
from google.protobuf import json_format
import random
import base64

conn_str = "esdb://localhost:2111,localhost:2112,localhost:2113?tls&rootCertificate=./tests/certs/ca/ca.crt&nodePreference=RANDOM"
client = EventStoreDBClient(conn_str)

# In case you need authentication for a specific user...
credentials = None
default_user = {"username": "******", "password": "******"}
credentials = base_options.as_credentials(**default_user)

client.delete_stream("some-stream", expected_version="ANY")

# Write some events...
n_events = 20
events = [JSONEventData(f"Event-{i + 1}", {"idx": i + 1}) for i in range(n_events)]
stream_name = "some-stream"
result = client.append_to_stream(stream_name, expected_version="ANY", events=events)

client._initialize_subscriptions_manager()

class EventsCounter:
    def __init__(self):
        self.events_processed = 0
"""
Run users examples to check authentication.
"""

from pprint import pprint
from eventstore_grpc.options import base_options
from eventstore_grpc import EventStoreDBClient, JSONEventData

conn_str = "esdb://localhost:2111,localhost:2112,localhost:2113?tls&rootCertificate=./tests/certs/ca/ca.crt"
default_user = {"username": "******", "password": "******"}
credentials = base_options.as_credentials(**default_user)

client = EventStoreDBClient(conn_str)

# Create new admin user.
new_user = {
    "login_name": "john-doe",
    "password": "******",
    "full_name": "John Doe",
    "groups": ["$admins", "event-store-guys"],
}
print("Creating new user:"******"login_name"],
                                       credentials=credentials)
print("\nUSER DETAILS:")
for elm in user_details:
    print(f"FULL  NAME: {elm.user_details.full_name}")
from eventstore_grpc import EventStoreDBClient
from eventstore_grpc.options import base_options

conn_str = "esdb://localhost:2111,localhost:2112,localhost:2113?tls&rootCertificate=./tests/certs/ca/ca.crt"
client = EventStoreDBClient(conn_str)

# In case you need authentication for a specific user...
credentials = None
default_user = {"username": "******", "password": "******"}
credentials = base_options.as_credentials(**default_user)

# Each client's method passes **kwargs down to the grpc method.
if credentials:
    cluster_info = client.get_cluster_info(credentials=credentials)
else:
    cluster_info = client.get_cluster_info()

print(cluster_info)
from eventstore_grpc import EventStoreDBClient, JSONEventData, constants
from eventstore_grpc.options import base_options
from pprint import pprint
import uuid
from eventstore_grpc.proto import streams_pb2
import time

conn_str = "esdb://localhost:2111,localhost:2112,localhost:2113?tls&rootCertificate=./tests/certs/ca/ca.crt"
client = EventStoreDBClient(conn_str)

# In case you need authentication for a specific user...
credentials = None
default_user = {"username": "******", "password": "******"}
credentials = base_options.as_credentials(**default_user)

event_1_id = str(uuid.uuid4())
stream = f"some-stream-to-read-from-{uuid.uuid4()}"
expected_version = constants.ANY
event_1 = JSONEventData(
    type="first-event",
    data={"foo": "bar"},
    metadata={"is_test": True},
    event_id=event_1_id,
)
print("*** Event 1: ***")
pprint(event_1)

print(f"\nAppending event to stream (stream_name: {stream}).")
events = [event_1]
client.append_to_stream(
    stream=stream, expected_version=expected_version, events=events