from gumband_python_sdk.logging_handler import get_local_logger
from gumband_python_sdk.network_handler import NetworkHandler
from gumband_python_sdk.service_name import ServiceName

SERVICE = ServiceName.NOTIFICATIONS

local_logger = get_local_logger()

"""
NotificationService
====================
A service class for sending email notifications for a specific exhibit component.
This class is intended as a private class. Please use the Gumband service instead.
"""


class NotificationService:
    def __init__(
        self,
        exhibit_id: int,
        network_handler: NetworkHandler,
    ):
        """
        Initializes the NotificationService.

        Args:
            exhibit_id (int): The ID of the exhibit.
            network_handler (NetworkHandler): An instance of the network handler for API communication.
        """
        self.exhibit_id = exhibit_id
        self.network_handler = network_handler

    async def send_email(self, message: str):
        """
        Sends an email notification to subscribed users.
        Users may subscribe to these notifications through the Gumband UI.

        Args:
            message (str): The email message content to send.

        Raises:
            Exception: If the email notification fails to send.
        """
        try:
            endpoint = "/email"
            data = {"message": message, "type": "notify", "exhibitId": self.exhibit_id}
            await self.network_handler.post(service=SERVICE, endpoint=endpoint, data=data)
        except Exception:
            raise
