# ── Generated by Nexa Transpiler ──────────────────────────────
# This file was auto-generated from a .nexa source file.
# Do not edit directly — regenerate with: nexa compile <file>
# ─────────────────────────────────────────────────────────────
from __future__ import annotations
import asyncio, math, json, os, random, time as _time

# ── Nexa runtime stubs ───────────────────────────────────────
_nexa_modules = {}

print('=== Nexa v6 Showcase ===\n')
print('--- 1. Destructuring ---')
coords = [15.5, (- 42.0)]
lat, lon = coords
print(f"Latitude: {lat}, Longitude: {lon}")
user = {'name': 'Alice', 'role': 'admin', 'age': 28}
_tmp_1796581590352 = user
name = _tmp_1796581590352.get('name')
role = _tmp_1796581590352.get('role')
print(f"Name: {name}, Role: {role}")
print('\n--- 2. Sets ---')
my_set = {1, 2, 3, 3, 2, 'hello'}
print(f"Initial set: {my_set}")
my_set.add(4)
print(f"After add(4): {my_set}")
print(f"Contains 2? {2}")
evens = {2, 4, 6, 8}
odds = {1, 3, 5, 7}
primes = {2, 3, 5, 7}
print(f"Evens union Odds: {evens.union(odds)}")
print(f"Evens intersection Primes: {evens.intersection(primes)}")
print('\n--- 3. Regex Module (re) ---')
text = 'Contact us at support@nexa.ai or sales@nexa.ai'
pat = '[a-z]+@[a-z]+\\.[a-z]+'
emails = re.find_all(pat, text)
print(f"Found emails: {emails}")
masked = re.sub(pat, '***@***', text)
print(f"Masked text: '{masked}'")
match_res = re.match('Hello (\\w+)', 'Hello World!')
print(f"Match groups: {match_res['groups']}")
print('\n--- 4. SQLite DB Module (db) ---')
db_file = 'test_v6.db'
if fs.exists(db_file):
    fs.delete(db_file)
conn = db.connect(db_file)
db.execute(conn, 'CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, role TEXT)')
db.execute(conn, 'INSERT INTO users (name, role) VALUES (?, ?)', ['Alice', 'admin'])
db.execute(conn, 'INSERT INTO users (name, role) VALUES (?, ?)', ['Bob', 'user'])
rows = db.query(conn, 'SELECT * FROM users')
print(f"Users in DB:")
for r in rows:
    print(f"  ID: {r['id']}, Name: {r['name']}, Role: {r['role']}")
db.close(conn)
print('\n--- 5. Web Server Module (serve) ---')
def handle_ping(req):
    return {'status': 'ok', 'message': 'pong', 'method': req['method']}
def handle_echo(req):
    return {'method': req['method'], 'body': req['body']}
serve.get('/ping', handle_ping)
serve.post('/echo', handle_echo)
print('Starting server on port 8181 (background)...')
serve.start(8181, True)
time.sleep(1)
get_res = http.get('http://localhost:8181/ping')
print(f"GET /ping response: {get_res['body']}")
post_res = http.post('http://localhost:8181/echo', {'hello': 'world'})
print(f"POST /echo response: {post_res['body']}")
print('\n✅ All Nexa v6 features verified!')
