import re


def parse_course_sis(course_sis_id):
    """ return a dict of the info in a course sis id  """

    if not course_sis_id:
        return None

    # new format implemented 2016.02.08
    new_format_match = re.match(r'(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)', course_sis_id)
    if new_format_match:
        program = new_format_match.group(4)
        return {"term": '{}-{}'.format(new_format_match.group(1), new_format_match.group(2)),
                "session": new_format_match.group(3),
                "program": program,
                "number": ('N' if program.startswith('N') else program) + new_format_match.group(5),
                "type": new_format_match.group(6),
                "campus": new_format_match.group(7),
                "section": new_format_match.group(8)}

    old_format_match = re.match(r'(.*)-(.*)-(.*)-(.*)-(.*)-(.*)-(.*)', course_sis_id)
    if old_format_match:
        program = old_format_match.group(4)
        number_prefix = {
            'BSCI': 'BSCI',
            'GENED': 'NGE',
            'IPE': 'IPE',
            'NURSG': 'N',
            'OCCTH': 'OT',
            'PA': 'PA',
            'PM': 'PM',
            'PHYTH': 'PT'
        }[program]
        return {"term": old_format_match.group(1),
                "campus": old_format_match.group(2),
                "session": old_format_match.group(3),
                "program": program,
                "number": number_prefix + old_format_match.group(5),
                "type": old_format_match.group(6),
                "section": old_format_match.group(7)}

    return None