import os
import pandas as pd
from telegram.telegram_notify import send_telegram_message

REGIME_DIR = "/opt/airflow/data/regimes"

def notify_today_regime(asset: str):

    file_path = os.path.join(REGIME_DIR, f"{asset}_regimes.parquet")
    df = pd.read_parquet(file_path)

    today = df.iloc[-1]
    yesterday = df.iloc[-2]

    if today["market_regime_label"] == yesterday["market_regime_label"]:
        print("Regime unchanged. No notification.")
        return

    emoji = {
        "Bull": "🟢",
        "Bear": "🔴",
        "Sideways": "🟡"
    }

    message = f"""
📊 *Market Regime Update*

Asset: `{asset}`
Regime: {emoji[today['market_regime_label']]} *{today['market_regime_label']}*

Return: `{today['return']:.4f}`
Volatility: `{today['volatility']:.4f}`
Trend 50: `{today['trend_50']:.4f}`
Trend 200: `{today['trend_200']:.4f}`
Momentum: `{today['momentum']:.4f}`
"""

    send_telegram_message(message)
    print("Notification sent.")