from __future__ import annotations

import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
DATA = ROOT / "data"
EXE = ROOT / "dist" / "NexaOffice_WorkSuite" / "NexaOffice_WorkSuite.exe"


def main() -> int:
    payload = {
        "ok": EXE.exists(),
        "exe_path": str(EXE),
        "exe_exists": EXE.exists(),
        "exe_size": EXE.stat().st_size if EXE.exists() else 0,
        "dist_exists": (ROOT / "dist").exists(),
        "build_exists": (ROOT / "build").exists(),
        "backup_root_exists": (ROOT / "build_backups").exists(),
        "build_logs_exists": (ROOT / "build_logs").exists(),
        "manifest_latest_exists": (DATA / "build_manifest_latest.json").exists(),
    }
    try:
        DATA.mkdir(parents=True, exist_ok=True)
        (DATA / "build_result_latest.json").write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
    except Exception:
        pass
    print(json.dumps(payload, ensure_ascii=False, indent=2))
    return 0 if payload["ok"] else 1


if __name__ == "__main__":
    raise SystemExit(main())
