import os
import sys
from datetime import datetime


def main() -> int:
    plugin_dir = os.environ.get("ROBOCLIENT_PLUGIN_DIR", os.getcwd())
    run_text = f"Hello Plugin World run at {datetime.now().isoformat(timespec='seconds')}"
    with open(os.path.join(plugin_dir, "last-run.txt"), "a", encoding="utf-8") as log:
        log.write(run_text + "\n")

    print("Hello Plugin World")
    print(f"Python: {sys.version.split()[0]}")
    print(f"Plugin dir: {plugin_dir}")
    print(f"Robo data dir: {os.environ.get('ROBOCLIENT_DATA_DIR', '')}")
    print(f"Documents API: {os.environ.get('ROBOCLIENT_DOCUMENTS_API', '')}")
    print(f"Time: {datetime.now().isoformat(timespec='seconds')}")
    return 0


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