"""Print-readiness for the printable parts. Prefers trimesh (watertight check on the
actual STL); falls back to build123d solid validity (a single valid BREP solid exports
to a watertight, printable STL).
Usage: print_check.py
"""
import sys
sys.path.insert(0, "/data/cameron/repos/smith300_para_stuff")

STLS = ["wrap_holder.stl", "yoke_exact.stl"]

try:
    import trimesh
    for path in STLS:
        m = trimesh.load(path, force="mesh")
        bodies = m.split(only_watertight=False)
        print(f"{path}: watertight={m.is_watertight} winding_ok={m.is_winding_consistent} "
              f"bodies={len(bodies)} tris={len(m.faces)} vol={m.volume:.0f} "
              f"extents={tuple(round(v,1) for v in m.extents)}")
    sys.exit(0)
except Exception as e:
    print(f"(trimesh unavailable: {e}; using build123d solid validity)")

from wrap_holder import make_wrap_holder
from yoke_exact import make_yoke_exact

for name, fn in [("wrap_holder", make_wrap_holder), ("yoke_exact", make_yoke_exact)]:
    p = fn()
    sols = [s for s in p.solids() if s.volume > 1.0]
    valid = getattr(p, "is_valid", "?")
    vol = sum(s.volume for s in sols)
    bb = p.bounding_box()
    print(f"{name}: real_solids={len(sols)}  valid_BREP={valid}  vol={vol:.0f}mm3  "
          f"extents=({bb.size.X:.1f},{bb.size.Y:.1f},{bb.size.Z:.1f})mm  "
          f"-> {'PRINTABLE (single closed solid)' if len(sols)==1 and valid in (True,'?') else 'CHECK'}")
