'''Defines stateless utility functions
'''
from src.core import Atom


def is_intensional(atom: Atom):
    '''Checks if the atom is intensional. If true returns true, otherwise returns false

    Arguments:
        atom {Atom} -- Atom to be analyzed
    '''
    for term in atom.terms:
        if not term.isVariable:
            return False

    return True


def printProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█'):
    """
    Call in a loop to create terminal progress bar
    @params:
        iteration   - Required  : current iteration (Int)
        total       - Required  : total iterations (Int)
        prefix      - Optional  : prefix string (Str)
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
    """
    total -= 1
    percent = ("{0:." + str(decimals) + "f}").format(100 *
                                                     (iteration / float(total)))
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + '-' * (length - filledLength)
    print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end='\r')
    # Print New Line on Complete
    if iteration == total:
        print()


INTENSIONAL_REQUIRED_MESSAGE = 'Atom is not intensional'
