#!/usr/bin/env python3
from pathlib import Path
import json, sys
sys.path.insert(0,str(Path(__file__).resolve().parent))
from local_dictionary_service import add_custom_translation
p=Path(__file__).resolve().parent/"data"/"translation"/"ITHAKI_LEXICON_RESTORED_R10F31.json"
d=json.loads(p.read_text(encoding="utf-8")); added=0; failed=0
for row in d.get("entries",[]):
    el=str(row.get("el","")).strip(); en=str(row.get("en","")).strip(); kind=str(row.get("type") or ("phrase" if " " in el else "word"))
    if not el or not en: continue
    for src,dst,a,b in (("el","en",el,en),("en","el",en,el)):
        r=add_custom_translation(a,b,src,dst,kind)
        if r.get("ok"): added+=1
        else: failed+=1
print(f"RESTORED_LEXICON_SOURCE_ENTRIES={len(d.get('entries',[]))}")
print(f"RESTORED_LEXICON_DB_ROWS={added}")
print(f"RESTORED_LEXICON_FAILED={failed}")
print("RESTORED_LEXICON_R10F31=OK" if added else "RESTORED_LEXICON_R10F31=NO_ROWS")
