<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def renumerate_stages(pipeline):
 """Renumber Pipeline Stage reference IDs to account for dependencies. stage order is defined in the templates. The ``refId`` field dictates if a stage should be mainline or parallel to other stages. * ``master`` - A mainline required stage. Other stages depend on it * ``branch`` - A stage that should be ran in parallel to master stages. * ``merge`` - A stage thatis parallel but other stages still depend on it. Args: pipeline (dict):
 Completed Pipeline ready for renumeration. Returns: dict: Pipeline ready to be sent to Spinnaker. """

    stages = pipeline['stages']

    main_index = 0
    branch_index = 0
    previous_refid = ''

    for stage in stages:
        current_refid = stage['refId'].lower()
        if current_refid == 'master':
            if main_index == 0:
                stage['requisiteStageRefIds'] = []
            else:
                stage['requisiteStageRefIds'] = [str(main_index)]
            main_index += 1
            stage['refId'] = str(main_index)
        elif current_refid == 'branch':
            # increments a branch_index to account for multiple parrallel stages
            if previous_refid == 'branch':
                branch_index += 1
            else:
                branch_index = 0
            stage['refId'] = str((main_index * 100) + branch_index)
            stage['requisiteStageRefIds'] = [str(main_index)]
        elif current_refid == 'merge':
            # TODO: Added logic to handle merge stages.
            pass

        previous_refid = current_refid
        LOG.debug('step=%(name)s\trefId=%(refId)s\t' 'requisiteStageRefIds=%(requisiteStageRefIds)s', stage)

    return pipeline