# Path: sam/integrity.py
# def get_table_names(db):
# def get_all_subs(db):
# def get_all_dss(db):
# def check_db_access_MySQL(params):
# def check_db_access_SQLite(params):
# def check_and_fix_db_access(params):
# def check_and_fix_db_access_MySQL(params):
# def check_and_fix_db_access_SQLite(params):
# def check_shared_tables(db):
# def fix_shared_tables(db, missing_tables):
# def fix_UDF_MySQL(db):
# def fix_UDF_SQLite(db):
# def fill_port_table(db):
# def check_default_subscription(db):
# def fix_default_subscription(db, errors):
# def check_subscriptions(db):
# def fix_subscriptions(db, errors):
# def fix_default_rules(db):
# def check_settings(db):
# def fix_settings(db, errors):
# def check_data_sources(db):
# def fix_data_sources(db, errors):
# def check_sessions_table(db):
# def fix_sessions_table(db, is_missing):
# def check_plugins(db):
# def fix_plugins(db, errors):
# def check_integrity(db=None):
# def check_and_fix_integrity(db=None, params=None):


from sam import common, integrity

class DBPlugin(object):
    @staticmethod
    def checkIntegrity(db):
        """
        Checks if the database is correct and returns the equivalent to false if db is consistent.
        if db is healthy, return False, 
            examples: False, 0, [] or {}
        if db is unhealthy return something useful for the fixIntegrity function, such as a list of missing tables
            example: {'missing': ['s1_mytable', 's3_mytable'], 'malformed': ['s2_mytable']} 
        
        :param db: database connection
        :return: False or equivalent iff consistent.
        """
        raise NotImplementedError

    @staticmethod
    def fixIntegrity(db, errors):
        """
        
        :param db: database connection 
        :param errors: the result of checkIntegrity function, ideally with helpful info on what to fix.
        :return: True if fixed, False if failed to fix.
        """
        raise NotImplementedError

    @staticmethod
    def simple_sub_table_check(*table_format_strings):
        @staticmethod
        def check(db):

# Path: sam/integrity.py
# def get_table_names(db):
# def get_all_subs(db):
# def get_all_dss(db):
# def check_db_access_MySQL(params):
# def check_db_access_SQLite(params):
# def check_and_fix_db_access(params):
# def check_and_fix_db_access_MySQL(params):
# def check_and_fix_db_access_SQLite(params):
# def check_shared_tables(db):
# def fix_shared_tables(db, missing_tables):
# def fix_UDF_MySQL(db):
# def fix_UDF_SQLite(db):
# def fill_port_table(db):
# def check_default_subscription(db):
# def fix_default_subscription(db, errors):
# def check_subscriptions(db):
# def fix_subscriptions(db, errors):
# def fix_default_rules(db):
# def check_settings(db):
# def fix_settings(db, errors):
# def check_data_sources(db):
# def fix_data_sources(db, errors):
# def check_sessions_table(db):
# def fix_sessions_table(db, is_missing):
# def check_plugins(db):
# def fix_plugins(db, errors):
# def check_integrity(db=None):
# def check_and_fix_integrity(db=None, params=None):


# Path: sam/models/base.py
from sam import common, integrity


class DBPlugin(object):
    @staticmethod
    def checkIntegrity(db):
        """
        Checks if the database is correct and returns the equivalent to false if db is consistent.
        if db is healthy, return False, 
            examples: False, 0, [] or {}
        if db is unhealthy return something useful for the fixIntegrity function, such as a list of missing tables
            example: {'missing': ['s1_mytable', 's3_mytable'], 'malformed': ['s2_mytable']} 
        
        :param db: database connection
        :return: False or equivalent iff consistent.
        """
        raise NotImplementedError

    @staticmethod
    def fixIntegrity(db, errors):
        """
        
        :param db: database connection 
        :param errors: the result of checkIntegrity function, ideally with helpful info on what to fix.
        :return: True if fixed, False if failed to fix.
        """
        raise NotImplementedError

    @staticmethod
    def simple_sub_table_check(*table_format_strings):
        @staticmethod
        def check(db):

            all_tables = set(integrity.get_table_names(db))