# --- VIDESH CHALO: PUSH NOTIFICATION ENGINE v1.0 ---
import requests
import json
import os

def send_videsh_chalo_push(title, message, url, image_url=None):
    """
    Universal function to send push notifications via OneSignal REST API.
    """
    # 🛡️ Get Keys from environment variables (Security)
    APP_ID = "e93f40d7-08e7-4345-aaa0-c0bff6397a16" # Dashbaord se milega
    API_KEY = os.environ.get('ONESIGNAL_REST_API_KEY') 

    if not API_KEY:
        print("PUSH_ERROR: REST API Key missing in environment variables.")
        return

    header = {
        "Content-Type": "application/json; charset=utf-8",
        "Authorization": f"Basic {API_KEY}"
    }

    payload = {
        "app_id": APP_ID,
        "included_segments": ["Subscribed Users"], # Sabhi ko bhejega
        "headings": {"en": title},
        "contents": {"en": message},
        "url": url, # Click karne par kahan jayega
        "chrome_web_image": image_url, # Android/Chrome mein badi photo dikhegi
    }

    try:
        response = requests.post(
            "https://onesignal.com/api/v1/notifications",
            headers=header,
            data=json.dumps(payload)
        )
        print(f"PUSH_SUCCESS: Notification sent! Status: {response.status_code}")
        return response.json()
    except Exception as e:
        print(f"PUSH_CRITICAL_ERROR: {str(e)}")
        return None