from parallels.core.hosting_repository.database_user import DatabaseUserModel
from parallels.plesk.hosting_repository.database_user import PleskDatabaseUserModel
from parallels.plesk_multi_server.hosting_repository.base import PleskMultiServerBaseModel


class PleskMultiServerDatabaseUserModel(DatabaseUserModel, PleskMultiServerBaseModel):
    def create_from_dump(self, database_user_dump, subscription_name, is_assimilate=False):
        """Create database user in target panel

        :type database_user_dump: parallels.core.dump.data_model.DatabaseUser
        :type subscription_name: str
        :type is_assimilate: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseUserModel(server).create_from_dump(
            database_user_dump, subscription_name, is_assimilate
        )

    def create(self, database_user, subscription_name):
        """Create database user in target panel

        :type database_user: parallels.core.hosting_repository.database_user.CreateDatabaseUserEntity
        :type subscription_name: str | unicode
        :return:
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseUserModel(server).create(
            database_user, subscription_name
        )

    def is_exists_by_subscription(self, subscription_name, database_user_name):
        """Check if database user with given name exists in target panel

        :type subscription_name: str
        :type database_user_name: str
        :rtype: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseUserModel(server).is_exists_by_subscription(subscription_name, database_user_name)
