import random as rd

class Generate:
    
    def __init__(self,columns :list = ["first_name","gender","age"],data :list =[["mutela","steve","ngalamulume"],["M","M","M"],[27,28,28,30]]):
        """
    Help on module Generate:
    NAME :
        Generate  - Generate data with column
    
    CONSTRUCTOR :
        columns [list]: it's Columns of your data
        data     [list]: it's your data. it's list of lists

    METHODS     :

        - generateOne() 
        - generateMany(rows) : 

    """
        self.columns = columns
        self.data = data
        self.value = None

            #return self.data
    def generateOne(self) -> dict: # Return a generate data [dict]
        """
        return a dictionnary data 

        Exemple :
        >>> jane = Generate(columns=['name','age'],data=[['jane','doe'],[28,29]])
        >>> jane.generateOne()
            {'name': 'jane', 'age': 28}
            

        """
       
        choice = lambda values : rd.choice(values) # method choice a value
        val = {}
        for i,column in enumerate(self.columns):
            if (column == "gender" or column == "sex" or column =="sexe") and "lastname" in self.columns:
                val[column] = "F" if val["lastname"].istitle() else "M"
            else:  
                try:
                        
                    #rd.shuffle(self.data[i])
                    val[column] = choice(self.data[i])
                except Exception as e:
                    print(f"Error : {e} :")
                    print(f"\tNot list data for Columns [ '{column}' ].\ncolumn [{column}] deleted!\n")
                    self.columns.remove(column)
                    continue
            
        self.value = val
        
        return self.value
    
    def generateMany(self,rows) -> list: # Return many data [list]

        """
            return list of data
        
            ARGS:
                rows : numbers of rows for your data

            Exemple :
            >>> jane = Generate(columns=['name','age'],data=[['jane','doe'],[28,29]])
            >>> jane.generateMany(3)
            [{'name': 'jane', 'age': 30}, {'name': 'doe', 'age': 30}, {'name': 'jane', 'age': 28}]
        """
        values = []
        for d in range(rows):
            values.append(self.generateOne())

        self.value = values
        return self.value
