from os import getenv

from sqgen_risk.client import Client
from sqgen_risk.config import Settings

# Initialize the client with custom settings (optional)
settings = Settings(BASE_URL=getenv("SAAS_BASE_URL", "https://api.example.com"))
client = Client()

# Authenticate using credentials from environment variables
email = getenv("SAAS_EMAIL")
password = getenv("SAAS_PASSWORD")
if not email or not password:
    raise RuntimeError("Missing required environment variables")  # noqa: TRY003

token = client.authenticate(email=email, password=password)
print(f"Authenticated successfully. Token: {token}")

# List available models
models = client.list_models()
print("\nAvailable models:")
for model in models:
    print(f"- {model.name} (ID: {model.model_id})")

# Submit an inference request
inference = client.create_inference(model_id="model-123", file_path="data.csv")
print(f"\nCreated inference request: {inference.inference_request_id}")

# Check inference status and get results
result = client.get_inference_result(inference.inference_request_id)
if result is None:
    print("Inference is still processing...")
else:
    print("Inference completed. Saving results...")
    with open("result.csv", "wb") as f:
        f.write(result)

# List all inferences
inferences = client.list_inferences()
print("\nAll inference requests:")
for inf in inferences:
    print(f"- ID: {inf.inference_request_id}, Model: {inf.model_id}, Created: {inf.created_at}")
