'''
Created on Sep 26, 2021

@author: immanueltrummer
'''
import codexdb.deprecated.code_gen.generic

class Cgenerator(codexdb.deprecated.code_gen.generic):
    """ Generates C code. """
    
    @abstractmethod
    def execute(self, db_id, question, generated):
        """ Execute generated code and return output.
        
        Args:
            db_id: database identifier
            question: generated code answers this question
            generated: code generated by Codex
        
        Returns:
            output when executing generated code
        """
        pass
         
    @abstractmethod   
    def _add_context(self):
        """ Add code creating context (e.g., required libraries). 
        
        Returns:
            prioritized snippets (priority, snippet)
        """
        pass
        
    @abstractmethod
    def _add_data_constraints(self, db_json):
        """ Add code illustrating foreign key constraints.
        
        Args:
            db_json: json description of database
        
        Returns:
            list of snippets with associated priority
        """
        pass
    
    @abstractmethod
    def _add_data_load(self, db_json, tbl_idx):
        """ Add code for loading a specific table. 
        
        Args:
            db_json: description of database schema
            tbl_idx: index of table to load
        
        Returns:
            snippets with associated priority
        """
        pass
    
    @abstractmethod
    def _add_data_samples(self, db_json, tbl_idx):
        """ Adds samples from table rows (e.g., via comments).
        
        Args:
            db_json: JSON description of database schema
            tbl_idx: index of current table
        
        Returns:
            list of snippets with priority
        """
        pass
    
    @abstractmethod
    def _add_data_schema(self, db_json, tbl_idx):
        """ Add code describing table columns.
        
        Args:
            db_json: description of database schema
            tbl_idx: describe schema of this table
        
        Returns:
            list of tuples (priority and snippet)
        """
        pass
    
    @abstractmethod
    def _add_data_types(self, db_json, tbl_idx):
        """ Add description of data types. 
        
        Args:
            db_json: JSON description of database
            tbl_idx: add column types for this table
        
        Returns:
            list of tuples (priority and snippet)
        """
        pass
    
    def _add_examples(self, db_json, question):
        """ Add examples for task to solve.
        
        Args:
            db_json: JSON description of database schema
            question: we ultimately want to answer this query
        
        Returns:
            list of snippets with associated priority
        """
        pass
        
    def _add_task(self, db_json, question, start_priority):
        """ Add code describing task to solve.
        
        Args:
            db_json: JSON description of database schema
            question: ultimately we want to answer this question
            start_priority: priority of first produced line
        
        Returns:
            list of snippets with associated priority
        """
        return [(start_priority, f'// {question}')]