from datetime import datetime

class Member:

    """Represente un membre dans la base de donnee de l'umons """

    def __init__(self, name, surname, faculty, section, register_date = datetime.now().strftime("%Y%m%d"), seen = 0, seen_dates = list()):
        """TODO: to be defined.

        :seen: number of time he came to CPUMONS 
        :seen_dates: date when he came 

        """

        self._name = name
        self._surname = surname
        self._mail = f"{name}.{surname}@studen.umons.ac.be"
        self._faculty = faculty
        self._section = section
        self._register_date = register_date
        self._seen = seen
        self._seen_dates = seen_dates

    def __str__(self):
        return f"{self._name} {self._surname}, {self._faculty} -> {self._section}; seen {self._seen} time(s)"

    def addSeen(self, date = datetime.now().strftime("%Y%m%d")):
        self._seen += 1
        self._seen_dates.append(date)

def interaction_menu(mbr_list):
    print("""
1) Insert new member
2) List members
3) Delete a member
4) Update member
5) Quit
          """)
    try:
        menu_selection = int(input("select your action: "))
    except:
        return True

    if menu_selection == 1:  # Insert new member
        name, surname, faculty, section = input("enter: <name surname faculty section> (with space between each input): ").split(' ')
        mbr_list.append(Member(name, surname, faculty, section))
    elif menu_selection == 2:  # List members
        for k, v in enumerate(mbr_list):
            print(k, v)
    elif menu_selection == 3:  # Delete a member
        toDelUser = input("enter the index of the user you want to delete: ")
        mbr_list.pop(toDelUser)
    elif menu_selection == 4:  # Update member
        toUpdateUser = int(input("enter the index of the user you want to update: "))
        datetime = input("enter the date where he has been seen ( let blank for the current date ): ")
        if not datetime:
            mbr_list[toUpdateUser].addSeen()
        else:
            mbr_list[toUpdateUser].addSeen(datetime)
    else:  # Menu error/quit
        return False
    return True

if __name__ == "__main__":
    user_list = list()
    exit = False
    while not exit:
        exit = not interaction_menu(user_list)
