from parallels.core.actions.base.common_action import CommonAction
from parallels.plesk.source.web.utils.status_storage import StatusStorage


# noinspection PyAbstractClass
class SiteMigrationAction(CommonAction):
    """Base action for all site migration actions
    """

    def on_exception(self, global_context, exception):
        """Handle unhandled exceptions

        :type global_context: parallels.plesk.source.web.global_context.WebGlobalMigrationContext
        :type exception: Exception
        :rtype: None
        """
        if global_context.site_objects_safe is not None and global_context.site_migration_list is not None:
            global_context.site_objects_safe.add_overall_issue(
                self.get_failure_message(global_context), exception,
                global_context.list_migrated_applications(),
                global_context.list_independent_migrated_folders(),
                global_context.list_independent_migrated_databases()
            )

    def get_pre_requirement_actions(self):
        """Get list of pre-requirements to execute that action: list of action classes.

        If any of these pre-requirements were not executed or execution failed, then this action won't be executed.

        :rtype: list[object]
        """
        return []

    @staticmethod
    def get_storage_status_type():
        """Category for status in status storage:

        We want to have separate statuses for different operation, e.g. for import and post-checks,
        The function returns where to put the status - see
        parallels.plesk.source.web.utils.status_storage.StatusStorage.STORAGE_STATUS_TYPE_* constants

        :rtype: str | unicode
        """
        return StatusStorage.STORAGE_STATUS_TYPE_COMMON_STATUS

    @staticmethod
    def get_storage_issue_type():
        """Category for issues in status storage:

        We want to have separate issues for different operation, e.g. for import and post-checks,
        The function returns where to put the issues - see
        parallels.plesk.source.web.utils.status_storage.StatusStorage.STORAGE_ISSUES_TYPE_* constants

        :rtype: str | unicode
        """
        return StatusStorage.STORAGE_ISSUES_TYPE_COMMON_ISSUES
