from go.vumitools.conversation.definition import (
    ConversationDefinitionBase, ConversationAction)


class ViewLogsAction(ConversationAction):
    action_name = 'view_logs'
    action_display_name = 'View Sandbox Logs'
    redirect_to = 'jsbox_logs'


class ConversationDefinition(ConversationDefinitionBase):
    conversation_type = 'jsbox'
    conversation_display_name = 'Javascript App'

    actions = (ViewLogsAction,)

    def configured_endpoints(self, config):
        return []

from go.vumitools.conversation.definition import (
    ConversationDefinitionBase, ConversationAction)


class ViewLogsAction(ConversationAction):
    action_name = 'view_logs'
    action_display_name = 'View Sandbox Logs'
    redirect_to = 'jsbox_logs'


class ConversationDefinition(ConversationDefinitionBase):
    conversation_type = 'jsbox'
    conversation_display_name = 'Javascript App'

    actions = (ViewLogsAction,)

    def configured_endpoints(self, config):
        # TODO: make jsbox apps define these explicitly and
        #       update the outbound resource to check and
        #       complain if a jsbox app sends on an endpoint
        #       it hasn't defined.
        app_config = config.get("jsbox_app_config", {})
        sandbox_config = app_config.get("config", {})
        sms_tag = sandbox_config.get("sms_tag")
        try:
            pool, tag = sms_tag
        except Exception:
            return []
        return ["%s:%s" % (pool, tag)]

Implement extra endpoints for Javascript apps.