import sqlite3
import os

db_path = 'build/Desktop_Qt_5_15_2_MSVC2019_64bit-Debug/components.db'

if os.path.exists(db_path):
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    # Проверяем варианты
    cursor.execute("SELECT id, name FROM variants")
    variants = cursor.fetchall()
    print("Variants:")
    for variant in variants:
        print(f"  ID: {variant[0]}, Name: {variant[1]}")
    
    # Проверяем вариативные свойства
    cursor.execute("SELECT COUNT(*) FROM variant_properties")
    variant_props_count = cursor.fetchone()[0]
    print(f"\nVariant properties count: {variant_props_count}")
    
    if variant_props_count > 0:
        # Показываем несколько примеров вариативных свойств
        cursor.execute("""
            SELECT vp.component_id, c.designator, v.name, vp.property_name, vp.property_value 
            FROM variant_properties vp
            JOIN components c ON vp.component_id = c.id
            JOIN variants v ON vp.variant_id = v.id
            LIMIT 10
        """)
        variant_props = cursor.fetchall()
        print("\nVariant properties examples:")
        for prop in variant_props:
            print(f"  Component {prop[1]} (ID: {prop[0]}) in variant '{prop[2]}': {prop[3]} = {prop[4]}")
    
    # Проверяем компоненты для каждого варианта
    for variant in variants:
        variant_id, variant_name = variant
        cursor.execute("""
            SELECT COUNT(*) FROM component_variants 
            WHERE variant_id = ?
        """, (variant_id,))
        component_count = cursor.fetchone()[0]
        print(f"\nVariant '{variant_name}' has {component_count} components")
        
        if component_count > 0:
            cursor.execute("""
                SELECT c.designator, cv.is_fitted 
                FROM component_variants cv
                JOIN components c ON cv.component_id = c.id
                WHERE cv.variant_id = ?
                LIMIT 5
            """, (variant_id,))
            components = cursor.fetchall()
            print("  Sample components:")
            for comp in components:
                print(f"    {comp[0]} (fitted: {comp[1]})")
    
    conn.close()
else:
    print("Database file not found!") 