from parallels.core.hosting_repository.database import DatabaseModel
from parallels.plesk.hosting_repository.database import PleskDatabaseModel
from parallels.plesk_multi_server.hosting_repository.base import PleskMultiServerBaseModel


class PleskMultiServerDatabaseModel(DatabaseModel, PleskMultiServerBaseModel):
    def create_from_dump(self, database_dump, subscription_name, is_assimilate=False):
        """Create database in target panel

        :type database_dump: parallels.core.dump.data_model.Database
        :type subscription_name: str
        :type is_assimilate: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseModel(server).create_from_dump(
            database_dump, subscription_name, is_assimilate
        )

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

        :type database: parallels.core.hosting_repository.database.CreateDatabaseEntity
        :type subscription_name: str | unicode
        :rtype: None
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseModel(server).create(
            database, subscription_name
        )

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

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

    def get_list_by_subscription(self, subscription_name, db_type):
        """Retrieve list of databases in panel for given subscription

        :type subscription_name: str | unicode
        :type db_type: str | unicode
        :rtype: list[parallels.core.hosting_repository.database.DatabaseEntity]
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDatabaseModel(server).get_list_by_subscription(subscription_name, db_type)
