from parallels.core import get_logger
from parallels.core.actions.base.common_action import CommonAction
from parallels.core.reports.model.issue import Issue
from parallels.plesk.source.plesk import messages
from parallels.plesk.source.plesk.actions.utils import get_target_plesk_server

logger = get_logger(__name__)


class CheckTransferErrorDocsAction(CommonAction):
    def get_description(self):
        return messages.ACTION_CHECK_TRANSFER_ERROR_DOCUMENTS

    def get_failure_message(self, global_context):
        return messages.ACTION_CHECK_TRANSFER_ERROR_DOCUMENTS_FAILED

    def is_critical(self):
        return False

    def filter_action(self, global_context):
        target_plesk_server = get_target_plesk_server(global_context)
        return target_plesk_server.is_windows() and target_plesk_server.get_plesk_version() >= (18, 0, 31)

    def run(self, global_context):
        global_context.pre_check_report.add_issue(
            'check_transfer_error_docs',
            Issue.SEVERITY_WARNING,
            messages.ACTION_CHECK_TRANSFER_ERROR_DOCUMENTS_TRANSFER_IS_NOT_POSSIBLE,
            messages.ACTION_CHECK_TRANSFER_ERROR_DOCUMENTS_TRANSFER_IS_NOT_POSSIBLE_SOLUTION
        )
