"""Check inventory data in database"""
from app.core.database import SessionLocal
from sqlalchemy import text

db = SessionLocal()

# Check products table structure
result = db.execute(text("""
    SELECT column_name
    FROM information_schema.columns
    WHERE table_name='products'
    ORDER BY ordinal_position
"""))
cols = [row[0] for row in result.fetchall()]
print(f"Products columns: {cols}")

# Check products
result = db.execute(text("SELECT COUNT(*) FROM products"))
print(f"\nTotal products: {result.scalar()}")

# Check HQ inventory data
result = db.execute(text("SELECT COUNT(*) FROM headquarters_inventory"))
print(f"HQ inventory rows: {result.scalar()}")

# Check HQ inventory details
result = db.execute(text("""
    SELECT h.product_id, h.total_received_quantity, h.available_for_allocation,
           h.average_cost_per_unit, h.total_cost_value
    FROM headquarters_inventory h
    LIMIT 10
"""))
print("\nHQ inventory items:")
for row in result.fetchall():
    print(f"  {row}")

# Check branch inventory allocations
result = db.execute(text("SELECT COUNT(*) FROM branch_inventory_allocations"))
print(f"\nBranch inventory allocations: {result.scalar()}")

# Sample products
result = db.execute(text("""
    SELECT p.id, p.name, p.sku, p.cost_price, p.category
    FROM products p
    ORDER BY p.name
    LIMIT 20
"""))
print("\nProducts:")
