def find_best_min_wage_fee_in_plans(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 1
    if env:
        best = env.default_min_wage_fee
    for plan in plans:
        if plan.min_wage_fee < best:
            best = plan.min_wage_fee

    return best

def find_best_wage_factor_in_plans(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 1
    if env:
        best = env.default_wage_factor
    for plan in plans:
        if plan.wage_factor < best:
            best = plan.wage_factor

    return best

def find_best_tax_factor_in_plans(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 1
    if env:
        best = env.default_tax_factor
    for plan in plans:
        if plan.tax_factor < best:
            best = plan.tax_factor

    return best


def find_best_max_institutes_per_user_in_plans(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 0
    if env:
        best = env.default_max_institutes_per_user
    for plan in plans:
        if plan.max_institutes_per_user > best:
            best = plan.max_institutes_per_user

    return best


def find_best_max_collaborators_per_institute(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 0
    if env:
        best = env.default_max_collaborators_per_institute
    for plan in plans:
        if plan.max_collaborators_per_institute > best:
            best = plan.max_collaborators_per_institute

    return best


def find_best_max_question_banks_per_institute(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass

    best = 0
    if env:
        best = env.default_max_question_banks_per_institute
    for plan in plans:
        if plan.max_question_banks_per_institute and plan.max_question_banks_per_institute > best:
            best = plan.max_question_banks_per_institute

    return best


def find_best_max_questions_per_question_bank(plans, env=None):
    if len(plans) == 0 and not env:
        # TODO critical error
        pass
    best = 0
    if env:
        best = env.default_max_questions_per_question_bank
    for plan in plans:
        
        if plan.max_questions_per_question_bank is not None and plan.max_questions_per_question_bank > best:
            best = plan.max_questions_per_question_bank

    return best
