from configs.connections import connect_graph
import logging
logger = logging.getLogger(__name__)
from flask import current_app

def job_label(skip_count,page_size):
    try:
        cql = f"""
        MATCH (n:jobLabel) 
        with n.name as name
        ORDER BY id(n) desc
        SKIP {skip_count}
        LIMIT {page_size}
        return collect(name) as label_list
        """
        label_list = connect_graph.run(cql).evaluate()
        total_query = f"MATCH (n:jobLabel)  RETURN COUNT(n) AS total"
        total_result = connect_graph.run(total_query).evaluate()
        return label_list,total_result
    except Exception as e:
        current_app.logger.error(f'job_label error:{e}')
        return ""


def enterprise_label(skip_count,page_size):
    try:
        cql = f"""
            MATCH (n:enterpriseLabel) 
            with n.name as name
            ORDER BY id(n) desc
            SKIP {skip_count}
            LIMIT {page_size}
            return collect(name) as label_list
            """
        label_list = connect_graph.run(cql).evaluate()
        total_query = f"MATCH (n:enterpriseLabel)  RETURN COUNT(n) AS total"
        total_result = connect_graph.run(total_query).evaluate()
        return label_list, total_result

    except Exception as e:
        current_app.logger.error(f'enterprise_label error:{e}')
        return ""



def seeker_label(skip_count,page_size):
    try:
        cql = f"""
                MATCH (n:seekerLabel) 
                with n.name as name
                ORDER BY id(n) desc
                SKIP {skip_count}
                LIMIT {page_size}
                return collect(name) as label_list
                """
        label_list = connect_graph.run(cql).evaluate()
        total_query = f"MATCH (n:seekerLabel)  RETURN COUNT(n) AS total"
        total_result = connect_graph.run(total_query).evaluate()
        return label_list, total_result

    except Exception as e:
        current_app.logger.error(f'seeker_label error:{e}')
        return ""