import warnings



def remove_forced(logger, model, universe, force_removal):
    
    
    if force_removal != '-':
        removed_rids = []
        forced_rids = force_removal.split(',')
        
        modeled_rids = [r.id for r in model.reactions]
        universal_rids = [r.id for r in universe.reactions]
        
        for rid in forced_rids: 
            
            if rid not in universal_rids:
                logger.info(f"Ignoring reaction ID '{rid}' since it's not included in the universe.")
                continue
            
            if rid not in modeled_rids:
                logger.debug(f"Requested reaction ID '{rid}' was already excluded from the model.")
            else:
                removed_rids.append(rid)

        # remove collected reactions:
        with warnings.catch_warnings():
            # avoid warnings like "python3.9/site-packages/cobra/core/group.py:147: UserWarning: need to pass in a list"
            warnings.simplefilter("ignore")
            model.remove_reactions(removed_rids) # this works also with rids instaead of Rs

        logger.info(f"Reactions forcibly removed: {removed_rids}.")
        


def remove_disconnected(logger, model):
    
    to_remove = []
    for m in model.metabolites:
        if len(m.reactions) == 0:
            to_remove.append(m)
    model.remove_metabolites(to_remove)
    logger.info(f"Removed {len(to_remove)} disconnected metabolites.")
    
    
