"""Thin wrapper around the WhatsApp Cloud API (Meta). Phase 2 — disabled until
WHATSAPP_ENABLED=true and Meta Business verification is complete.
"""
import requests
from flask import current_app

GRAPH_API_VERSION = "v20.0"


def send_text_message(to_phone: str, body: str) -> None:
    phone_number_id = current_app.config["WHATSAPP_PHONE_NUMBER_ID"]
    access_token = current_app.config["WHATSAPP_ACCESS_TOKEN"]

    url = f"https://graph.facebook.com/{GRAPH_API_VERSION}/{phone_number_id}/messages"
    headers = {"Authorization": f"Bearer {access_token}"}
    payload = {
        "messaging_product": "whatsapp",
        "to": to_phone,
        "type": "text",
        "text": {"body": body[:4096]},
    }

    response = requests.post(url, headers=headers, json=payload, timeout=10)
    response.raise_for_status()
