import logging


def fst_pruning(fsa, prune_threshold, n_best, openfst):
    """
    Apply pruning to a single FST. If using pruning, FST is modified.
    :param fst: FST object
    :param prune_threshold: Integer indicating how much to prune
    :param n_best: Integer indicating how many best outputs to keep
    :param openfst: OpenFST utility functions object
    :return: Pruned FSA object
    """

    if prune_threshold is not None and n_best is not None:
        logging.info('Starting prune+shortest path operation.')
        openfst.prune_with_shortest_path(fsa, prune_threshold, n_best)
    elif prune_threshold is not None:
        logging.info('Starting prune path operation.')
        openfst.prune(fsa, prune_threshold)
    elif n_best is not None:
        logging.info('Starting shortest path operation.')
        fsa = openfst.shortest_path(fsa, n_best)

    return fsa