# L-24 MCS 260 : library manager
"""
A library management system with classes
"""

from classcatalog import Catalog
from classpeople import People

def show_menu(who):
    """
    Shows the menu to the user
    and returns the choice made.
    """
    if who == -1:  # no one logged on
        print('Please log on')
        return 0
    else: # who == 0 is patron
        print('choose from the menu :')
        print('  1. log off')
        print('  2. show the collection')
        print('  3. check out a book')
        print('  4. return a book')
        if who == +1: # librarian
            print('  5. add a new book')
            print('  6. delete a book')
            print('  7. add a new user')
            print('  8. delete a user')
            print('  9. shut down')
        ansraw = input('Make your choice : ')
        return int(ansraw)

def act(pep, cat, chc, who):
    "Performs the requested action."
    result = who
    if chc == 0:
        result = pep.logon()
    elif chc == 1:
        pep.logoff()
        result = -1
    elif chc == 2:
        cat.show()
    elif chc == 3:
        cat.checkout()
    elif chc == 4:
        cat.checkin()
    elif chc == 5:
        cat.add()
    elif chc == 6:
        cat.delete()
    elif chc == 7:
        pep.add()
    elif chc == 8:
        pep.delete()
    return result

def main():
    "Main library management program."
    cat = Catalog()
    people = People()
    who = -1
    print('Welcome to our library!')
    while True:
        choice = show_menu(who)
        if choice == 9:
            break
        who = act(people, cat, choice, who)

main()
