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

Detects ma20 crossing above ma60 (golden cross). Auxiliary STRATEGY_SCORING signal
only -- never an independent BUY trigger. governance/todo/technical_signals_p4_adoption_plan.yaml P4-1.
"""
from __future__ import annotations

import argparse
import json
from pathlib import Path

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


def golden_cross_today(ma20: float | None, ma20_prev: float | None, ma60: float | None, ma60_prev: float | None) -> bool | None:
    if None in (ma20, ma20_prev, ma60, ma60_prev):
        return None
    return ma20_prev <= ma60_prev and ma20 > ma60


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

    result = {
        "formula_id": "GOLDEN_CROSS_SIGNAL_V1",
        "golden_cross_today": golden_cross_today(args.ma20, args.ma20_prev, args.ma60, args.ma60_prev),
        "hard_constraint": "auxiliary_signal_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())
