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

Feeds BREAKOUT_QUALITY_GATE_V2 -- never an independent BUY trigger.
governance/todo/technical_signals_p4_adoption_plan.yaml P4-4.
"""
from __future__ import annotations

import argparse
import json
from pathlib import Path

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


def evaluate(close_price: float | None, high52w: float | None) -> bool | None:
    if close_price is None or high52w is None:
        return None
    return close_price >= high52w


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

    result = {
        "formula_id": "FIFTY_TWO_WEEK_HIGH_TRIGGER_V1",
        "fifty_two_week_high_breakout": evaluate(args.close, args.high52w),
        "hard_constraint": "feeds_BREAKOUT_QUALITY_GATE_V2_only_not_buy_trigger",
    }
    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())
