import random


def MH_config(BIM):
    """
    Rules to identify a HAZUS WSF configuration based on BIM data

    Parameters
    ----------
    BIM: dictionary
        Information about the building characteristics.

    Returns
    -------
    config: str
        A string that identifies a specific configration within this buidling
        class.
    """

    year = BIM['year_built'] # just for the sake of brevity
    if year <= 1976:
        # MHPHUD
        bldg_tag = 'MHPHUD'
        if BIM['WBD']:
            shutters = random.random() < 0.45
        else:
            shutters = False
        # TieDowns
        TD = random.random() < 0.45

    elif year <= 1994:
        # MH76HUD
        bldg_tag = 'MH76HUD'
        if BIM['WBD']:
            shutters = random.random() < 0.45
        else:
            shutters = False
        # TieDowns
        TD = random.random() < 0.45

    else:
        # MH94HUD I, II, III
        if BIM['V_ult'] >= 100.0:
            shutters = True
        else:
            shutters = False
        # TieDowns
        if BIM['V_ult'] >= 70.0:
            TD = True
        else:
            TD = False
        bldg_tag = 'MH94HUD' + BIM['wind_zone']

    bldg_config = f"{bldg_tag}_" \
                  f"{int(shutters)}_" \
                  f"{int(TD)}_" \
                  f"{int(BIM['terrain'])}"
    return bldg_config