import firebase_admin,os
from firebase_admin import credentials,messaging
GoogleCredentialsPath = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'firebase/excitech.json')
cred = credentials.Certificate(GoogleCredentialsPath)
firebase_admin.initialize_app(cred)

# token = ["eDDMYLfqQxi87eoLdLicOC:APA91bHIYRLj9xvJa7SpqBnYa9Pac9VMnikkO1MB4vvrLRmylClasnq8vV-TK9g-22xTF1n9ouYHQz_Ho2Bgn0gxY0LLa_Ad6ofk3iKfxVWuI7qDrVcy1bxVSX7MVA8a3F81gEP0DIhx"]
def sendPush(title,msg,registration_token,dataObject=None):
    message = messaging.MulticastMessage(
        notification = messaging.Notification(
            title = title,
            body = msg,
        ),
        data = dataObject,
        tokens = registration_token
    )
    response = messaging.send_each_for_multicast(message)   
    if response.success_count > 0:
        print(f"Successfully sent {response.success_count} messages.")
    if response.failure_count > 0:
        print(f"Failed to send {response.failure_count} messages.")
        # Optional: print the reasons for failures
        for idx, resp in enumerate(response.responses):
            if not resp.success:
                print(f"Failed message {idx} with error: {resp.exception}")

    return response
    print('Successfully sent message:', response)
    # print('Successfully sent message:', response)