from parallels.core.utils.common import cached
from parallels.plesk.source.plesk.capability_dump.model import plesk_entity
from parallels.plesk.source.plesk.capability_dump.model.plesk import PleskCapabilityDumpModel
from parallels.plesk.source.plesk.capability_dump.utils import capability_data_dump
from parallels.plesk.source.plesk import messages


class PleskCapabilityDumpModel178(PleskCapabilityDumpModel):
    @cached
    @capability_data_dump(messages.DATA_DUMP_DISK_USAGE, {})
    def _get_all_plesk_disk_usage(self):
        """
        :rtype: dict[str|unicode, parallels.plesk.source.plesk.capability_dump.model.plesk_entity.disk_usage.DiskUsage]
        """
        # Comparing to Plesk 17.5, there is no "webapps" field
        rows = self._dump_agent.execute_sql("""
            SELECT `dom_id`, `httpdocs`, `httpsdocs`, `subdomains`, `web_users`, `anonftp`, `mysql_dbases`,
                `mssql_dbases`, `mailboxes`, `maillists`
            FROM `disk_usage`
        """)
        return {
            row['dom_id']: plesk_entity.DiskUsage(
                domain_id=row['dom_id'], httpdocs=row['httpdocs'], httpsdocs=row['httpsdocs'],
                subdomains=row['subdomains'], web_users=row['web_users'], anonftp=row['anonftp'],
                mysql_dbases=row['mysql_dbases'], mssql_dbases=row['mssql_dbases'], mailboxes=row['mailboxes'],
                maillists=row['maillists'],
                webapps=None,
            )
            for row in rows
        }
