from .grpc.darsman_notification_pb2 import MessagingRequest
from .grpc.darsman_notification_pb2_grpc import MessagingControllerStub

SUCCESS_CODE = "0"


def _singletonize_class_vars(cls):
    for attr_name, attr_value in cls.__dict__.items():
        if isinstance(attr_value, type):  # it's a class
            orig_cls = attr_value

            class SingletonWrapper(orig_cls):
                _instances = {}

                def __new__(cls, *args, **kwargs):
                    if cls not in cls._instances:
                        cls._instances[cls] = super().__new__(cls)
                    return cls._instances[cls]

            setattr(cls, attr_name, SingletonWrapper)
    return cls


class RequestMessages:
    SEND_MESSAGE = MessagingRequest


class RPCMethodNames:
    SEND_MESSAGE = "SendMessage"


@_singletonize_class_vars
class Stubs:
    MESSAGE = MessagingControllerStub


class NotificationTypes:
    SMS_NOTIFICATION = "sms"
    EMAIL_NOTIFICATION = "email"


class EventProTypes:
    LOGIN = "login"
    REGISTER = "register"
    WELCOME = "welcome"
    DISCOUNT_1MO_AFTER_REG = "discount_1mo_after_reg"
    HAPPY_BIRTHDAY = "hbd"
    CERTIFICATE_SUBMIT = "cert_submit"
    CERTIFICATE_EDIT = "cert_edit"
    MASTER_COURSE_INFORM = "edu_sup_inform"
    INITIAL_REGISTER = "init_course_reg"
    ROAD_MAP = "roadmap"
    CONSULT_REQUEST = "success_consult_req"
    DISCOUNT = "discount"
    MASTER_COURSE_REGISTER_FORM = "master_course_register_form"
    BASKET_MERKETING = "basket_merketing"
