#!/usr/bin/env python3

import sys
import os

sys.path.insert(0, "/home/ouaillaamiri/Development/Oit LAB/CaDaR")

from cadar import CaDaR


def debug_word(word):
    """Debug the processing of a single word through all stages"""
    print(f"\n=== Debugging: '{word}' ===")

    # Initialize CaDaR
    cadar = CaDaR()

    # Latin to Arabic
    arabic = cadar.bizi2ara(word)
    print(f"Latin → Arabic: '{word}' → '{arabic}'")

    # Arabic back to Latin (roundtrip)
    roundtrip = cadar.ara2bizi(arabic)
    print(f"Arabic → Latin: '{arabic}' → '{roundtrip}'")

    # Check if roundtrip is perfect
    if word == roundtrip:
        print("✅ Perfect roundtrip!")
    else:
        print(f"❌ Roundtrip failed: '{word}' ≠ '{roundtrip}'")

    print("-" * 40)


if __name__ == "__main__":
    # Test problematic words from benchmark
    test_words = [
        "walakin",  # had missing middle 'i'
        "nwrko",  # had middle 'w' mapped to 'o'
        "ghadi",  # had '8' instead of 'gh'
        "tri9",  # had missing middle 'i'
        "laa",  # vowel length issue: should roundtrip perfectly
    ]

    for word in test_words:
        debug_word(word)
