from __future__ import annotations

import argparse
import json
from pathlib import Path

try:
    from src.executor import run_engine
except ModuleNotFoundError:
    from executor import run_engine


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--input", required=True, help="input request json path")
    parser.add_argument("--output", required=True, help="output signal json path")
    args = parser.parse_args()

    root = Path(__file__).resolve().parents[1]
    payload = json.loads(Path(args.input).read_text(encoding="utf-8"))
    signal = run_engine(payload, root)
    Path(args.output).write_text(json.dumps(signal, ensure_ascii=False, indent=2), encoding="utf-8")
    print(json.dumps({"ok": True, "output": str(Path(args.output))}, ensure_ascii=False))
    return 0


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