#!/usr/bin/env python3
"""
Windows Path Compatibility Test
=============================

Testet die Kompatibilität des Batch-Uploaders mit verschiedenen Pfad-Formaten.
"""

from pathlib import Path
import os
import sys

def test_path_compatibility():
    """Testet verschiedene Pfad-Formate"""
    
    print("🧪 Path Compatibility Test")
    print("=" * 40)
    
    # Test verschiedene Pfad-Formate
    test_paths = [
        # Unix/Linux Pfade
        "/home/user/photos",
        "./relative/path",
        "../parent/dir",
        
        # Windows Pfade (simuliert)
        r"C:\Users\lotzm\Photos",
        r"C:\Users\lotzm\Nextcloud2\HH DropFolder with quota\=NutzerBildUploads=",
        r"D:\Backup Fotos\2024\Familie Schmidt",
        
        # Problematische Pfade
        "path with spaces",
        "path/with/äöü/unicode",
        "path-with-special=chars",
        
        # Relative Windows-Style (simuliert)
        r".\Windows\Style\Path",
        r"..\Parent\Windows\Path"
    ]
    
    print("📁 Pfad-Verarbeitung Test:")
    print()
    
    for i, test_path in enumerate(test_paths, 1):
        try:
            # Python pathlib verarbeitet automatisch cross-platform
            path_obj = Path(test_path)
            resolved = path_obj.resolve() if path_obj.exists() else "Pfad existiert nicht (OK für Test)"
            
            print(f"{i:2}. ✅ Input: {test_path}")
            print(f"     📍 Resolved: {resolved}")
            print(f"     📂 Parts: {path_obj.parts}")
            print(f"     🔧 Suffix: {path_obj.suffix}")
            print(f"     📝 Name: {path_obj.name}")
            print()
            
        except Exception as e:
            print(f"{i:2}. ❌ FEHLER: {test_path}")
            print(f"     💥 Error: {e}")
            print()
    
    print("🎯 Spezial-Test: Windows-Pfad mit Leerzeichen")
    print("-" * 50)
    
    # Simuliere Windows-Pfad Verhalten
    windows_path = r"C:\Users\lotzm\Nextcloud2\HH DropFolder with quota\=NutzerBildUploads="
    path_obj = Path(windows_path)
    
    print(f"Original: {windows_path}")
    print(f"Path Object: {path_obj}")
    print(f"Parts: {path_obj.parts}")
    print(f"Parent: {path_obj.parent}")
    print(f"Name: {path_obj.name}")
    
    # Struktur-Parsing Test (wie im batch_uploader.py)
    print(f"\n📊 Struktur-Parsing Test:")
    if len(path_obj.parts) >= 4:
        print(f"Jahr: {path_obj.parts[-4] if len(path_obj.parts) > 3 else 'N/A'}")
        print(f"Name: {path_obj.parts[-3] if len(path_obj.parts) > 2 else 'N/A'}")
        print(f"Projekt: {path_obj.parts[-2] if len(path_obj.parts) > 1 else 'N/A'}")
        print(f"Datei: {path_obj.parts[-1] if path_obj.parts else 'N/A'}")
    else:
        print("Pfad zu kurz für Struktur-Parsing")

if __name__ == "__main__":
    test_path_compatibility()
    
    print("\n✅ Path Compatibility Test abgeschlossen!")
    print("💡 Python pathlib.Path unterstützt automatisch:")
    print("   - Windows Pfade (C:\\, \\\\UNC)")
    print("   - Unix Pfade (/home, ./relative)")
    print("   - Leerzeichen und Sonderzeichen")
    print("   - Cross-platform Konvertierung")