from profiles.ProfileManager import update
class UIMessageManager:

    def __init__(self, bot):
        self.bot = bot

    def render(self, profile, chat_id, text, reply_markup=None, parse_mode="MarkdownV2"):
        if profile.ui_message_id:
            try:
                self.bot.edit_message_text(
                    text = text,
                    chat_id = chat_id,
                    message_id = profile.ui_message_id,
                    reply_markup = reply_markup,
                    parse_mode=parse_mode
                )
                return
            except Exception as e:
                print(e)
        msg = self.bot.send_message(
            chat_id=chat_id,
            text=text,
            reply_markup=reply_markup,
            parse_mode=parse_mode
        )
        profile.ui_message_id = msg.message_id
        update(profile)