import json, urllib.request

PB = "http://localhost:8102"

def post(path, data, token=None):
    req = urllib.request.Request(PB + path, data=json.dumps(data).encode(),
        headers={"Content-Type": "application/json", **({"Authorization": token} if token else {})})
    return json.load(urllib.request.urlopen(req))

def get(path, token=None):
    req = urllib.request.Request(PB + path, headers={"Authorization": token} if token else {})
    return json.load(urllib.request.urlopen(req))

tok = post("/api/collections/_superusers/auth-with-password",
           {"identity": "edelmar.edd@gmail.com", "password": "564712564712"})["token"]

try:
    col = get("/api/collections/consultas", tok)
except Exception as e:
    print("La coleccion 'consultas' NO existe o error:", e)
    raise SystemExit

print("=== Coleccion 'consultas' ===")
print("id:", col["id"], " type:", col.get("type"))
print("\n--- API Rules ---")
for r in ["listRule", "viewRule", "createRule", "updateRule", "deleteRule"]:
    print(f"  {r}: {col.get(r)!r}")
print("\n--- Campos ---")
for f in col.get("fields", []):
    extra = ""
    if f["type"] == "relation":
        extra = f" -> col {f.get('collectionId')}, maxSelect={f.get('maxSelect')}"
    if f["type"] == "select":
        extra = f" values={f.get('values')}"
    print(f"  {f['name']:16} {f['type']:10} required={f.get('required')}{extra}")
