from parallels.core.actions.utils.logging_properties import LoggingProperties
from parallels.core.logging import get_logger
from parallels.core.target_data_model import Model, Client, Subscription
from parallels.plesk.source.web import messages
from parallels.plesk.source.web.actions.base.site_migration import SiteMigrationAction

logger = get_logger(__name__)


class CreateModel(SiteMigrationAction):
    """Create target model description - technical object which is required by migration core"""

    def get_description(self):
        """Get short description of action as string

        :rtype: str | unicode
        """
        return messages.ACTION_DESCRIPTION_CREATE_MODEL

    def get_failure_message(self, global_context):
        """Get message for situation when action failed

        :type global_context: parallels.core.global_context.GlobalMigrationContext
        :rtype: str | unicode
        """
        return messages.ACTION_FAILED_CREATE_MODEL

    def get_logging_properties(self):
        """Get how action should be logged to migration tools end-user

        :rtype: parallels.core.actions.utils.logging_properties.LoggingProperties
        """
        return LoggingProperties(info_log=False, compound=False)

    def run(self, global_context):
        """Run action

        :type global_context: parallels.plesk.source.web.global_context.WebGlobalMigrationContext
        :rtype: None
        """
        global_context.target_model = Model(
            reseller_plans={},
            plans={},
            resellers={},
            clients={
                None: Client(login=None, password=None, personal_info=None, subscriptions=[
                    Subscription(
                        name=global_context.site_info_storage.get_target_subscription(),
                        plan_name=None, plan_addon_names=None, is_enabled=True, is_locked=False,
                        source='web', is_windows=False, sysuser_login=None, mail_service=True)
                ])
            }
        )
        global_context.safe.model = global_context.target_model
