#!/usr/bin/env python3
"""STRONG_CLOSE_SIGNAL_V1 — spec/formulas/domains/entry.yaml.

governance/todo/technical_signals_p4_adoption_plan.yaml P4-2.
"""
from __future__ import annotations

import argparse
import json
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
DEFAULT_OUT = ROOT / "Temp" / "strong_close_signal_v1.json"


def evaluate_strong_close(close_price: float, high_price: float, low_price: float) -> dict:
    if high_price == low_price:
        return {"close_position_pct": None, "strong_close": None}
    close_position_pct = (close_price - low_price) / (high_price - low_price) * 100
    return {"close_position_pct": close_position_pct, "strong_close": close_position_pct >= 80}


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--close", type=float, required=True)
    ap.add_argument("--high", type=float, required=True)
    ap.add_argument("--low", type=float, required=True)
    ap.add_argument("--out", default=str(DEFAULT_OUT))
    args = ap.parse_args()

    result = {"formula_id": "STRONG_CLOSE_SIGNAL_V1", **evaluate_strong_close(args.close, args.high, args.low)}
    out = Path(args.out)
    out.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
    print(json.dumps(result, ensure_ascii=False, indent=2))
    return 0


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