class SavedLinksCommand(Command):
    """
    Command /savedlinks
    Shows a list of the links that the user saved
    """
    COMMAND = 'savedlinks'

    def __init__(self, update: Update, context: CallbackContext):
        super().__init__(update, context)
        self.spotify_api_client = SpotifyAPIClient()

    def get_response(self):
        saved_links_response = self.spotify_api_client.get_saved_links(self.update.message.from_user.id)
        return self._build_message(saved_links_response), None

    @staticmethod
    def _build_message(saved_links_response: {}):
        if not saved_links_response:
            return 'You have not saved links'

        msg = '<strong>Saved links:</strong> \n'
        for saved_link in saved_links_response:
            link = saved_link.get('link')
            genres = Link.get_genres(link)
            msg += f'- {emojis.get_music_emoji(link.get("link_type"))} <a href="{link.get("url")}">{Link.get_name(link)}</a> ' \
                   f'({", ".join(genres) if genres else ""}). ' \
                   f'Saved at: {datetime.datetime.fromisoformat(saved_link.get("saved_at")).strftime(OUTPUT_DATE_FORMAT)}\n'
        return msg
class DeleteSavedLinksCommand(Command):
    """
    Command /deletesavedlinks
    Shows a list of buttons with the saved links and deletes them when clicking
    """
    COMMAND = 'deletesavedlinks'

    def __init__(self, update: Update, context: CallbackContext):
        super().__init__(update, context)
        self.spotify_api_client = SpotifyAPIClient()

    def get_response(self):
        keyboard = self._build_keyboard()
        if not keyboard:
            return 'You have not saved links', None
        return 'Choose a saved link to delete:', keyboard

    def _build_keyboard(self):
        saved_links_response = self.spotify_api_client.get_saved_links(self.update.message.from_user.id)
        if not saved_links_response:
            return None
        return DeleteSavedLinkButton.get_keyboard_markup(saved_links_response)