"""Probe product visibility for tenant scoping (run on server with PYTHONPATH=/opt/cnperp)."""
from app.core.database import SessionLocal
from app.models.inventory import Product
from app.models.branch import Branch

db = SessionLocal()
total = db.query(Product).count()
active = db.query(Product).filter(Product.active == True).count()
print(f"products_total={total} active={active}")
for p in db.query(Product).limit(5).all():
    br = db.query(Branch).filter(Branch.id == p.branch_id).first() if p.branch_id else None
    print(
        f"  id={p.id[:8]}.. qty={p.quantity} active={p.active} "
        f"branch_id={p.branch_id} branch_company={getattr(br, 'company_id', None)} name={p.name}"
    )
db.close()
