#!/usr/bin/env python3
"""
Debug script to check flow data for the 192.168.7.168 source
"""

import sys
sys.path.append('.')

from analyzer.analysis.core import EthernetAnalyzer

def debug_flow():
    analyzer = EthernetAnalyzer()
    
    # Load the sample file
    pcap_file = "1 PTPGM.pcapng"
    print(f"Loading {pcap_file}...")
    
    try:
        analyzer.analyze_pcap(pcap_file)  # Load the file
        
        # Find the flow with source 192.168.7.168
        target_flow = None
        for flow in analyzer.flows.values():
            if flow.src_ip == "192.168.7.168":
                target_flow = flow
                break
        
        if not target_flow:
            print("No flow found with source 192.168.7.168")
            print("Available flows:")
            for flow in analyzer.flows.values():
                print(f"  {flow.src_ip}:{flow.src_port} -> {flow.dst_ip}:{flow.dst_port}")
            return
        
        print(f"\n=== Flow: {target_flow.src_ip}:{target_flow.src_port} -> {target_flow.dst_ip}:{target_flow.dst_port} ===")
        print(f"Frame types: {len(target_flow.frame_types)} types")
        
        if target_flow.frame_types:
            for frame_type, stats in target_flow.frame_types.items():
                print(f"  - {frame_type}: {stats.count} packets")
        
        print(f"Enhanced decoder: {target_flow.enhanced_analysis.decoder_type}")
        
        # Check the subflow logic
        has_subflows_condition1 = len(target_flow.frame_types) > 1
        has_subflows_condition2 = target_flow.enhanced_analysis.decoder_type != "Standard"
        has_subflows = has_subflows_condition1 or has_subflows_condition2
        
        print(f"\nSubflow logic:")
        print(f"  Multiple frame types (>1): {has_subflows_condition1}")
        print(f"  Enhanced decoder (!='Standard'): {has_subflows_condition2}")
        print(f"  Should show subflows: {has_subflows}")
        print(f"  Should show timing in main panel: {not has_subflows}")
        
    except Exception as e:
        print(f"Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    debug_flow()