#!/usr/bin/env python3
"""
Test script for pipeline deployment functionality.

This script demonstrates the deploy feature without requiring actual dongles.
"""

import sys
import os
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt

# Add the current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from ui.dialogs.deployment import DeploymentDialog

def test_deployment_dialog():
    """Test the deployment dialog with sample pipeline data."""
    
    # Sample pipeline data (similar to what would be exported from the UI)
    sample_pipeline_data = {
        "project_name": "Test Fire Detection Pipeline",
        "description": "A test pipeline for demonstrating deployment functionality",
        "nodes": [
            {
                "id": "input_001",
                "name": "Camera Input",
                "type": "ExactInputNode", 
                "pos": [100, 200],
                "properties": {
                    "source_type": "Camera",
                    "device_id": 0,
                    "resolution": "1920x1080",
                    "fps": 30,
                    "source_path": ""
                }
            },
            {
                "id": "model_001",
                "name": "Fire Detection Model",
                "type": "ExactModelNode",
                "pos": [300, 200], 
                "properties": {
                    "model_path": "./models/fire_detection.nef",
                    "scpu_fw_path": "./firmware/fw_scpu.bin",
                    "ncpu_fw_path": "./firmware/fw_ncpu.bin",
                    "dongle_series": "520",
                    "num_dongles": 1,
                    "port_id": "28"
                }
            },
            {
                "id": "output_001", 
                "name": "Detection Output",
                "type": "ExactOutputNode",
                "pos": [500, 200],
                "properties": {
                    "output_type": "Stream",
                    "format": "JSON",
                    "destination": "tcp://localhost:5555",
                    "save_interval": 1.0
                }
            }
        ],
        "connections": [
            {
                "output_node": "input_001",
                "output_port": "output", 
                "input_node": "model_001",
                "input_port": "input"
            },
            {
                "output_node": "model_001",
                "output_port": "output",
                "input_node": "output_001", 
                "input_port": "input"
            }
        ],
        "version": "1.0"
    }
    
    app = QApplication(sys.argv)
    
    # Enable high DPI support
    app.setAttribute(Qt.AA_EnableHighDpiScaling, True)
    app.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
    
    # Create and show deployment dialog
    dialog = DeploymentDialog(sample_pipeline_data)
    dialog.show()
    
    print("Deployment dialog opened!")
    print("You can:")
    print("1. Click 'Analyze Pipeline' to see topology analysis")
    print("2. Review the configuration in different tabs")
    print("3. Click 'Deploy to Dongles' to test deployment process")
    print("(Note: Actual dongle deployment will fail without hardware)")
    
    # Run the application
    return app.exec_()

if __name__ == "__main__":
    sys.exit(test_deployment_dialog())