### DB inspect from CRM project to define DB state
def db_inspect(db):
    rep = []
    for k, v in db.items():
        if "id" in v:
            rep.append("{}({})".format(k, v["id"]))
        else:
            rep.append(str(k))

    print("Current Companies in DB: {}".format(', '.join(rep)))


### user id# auto create from CRM example; not currently utilized
class IdGen:
    def __init__(self, starting_id):
        self.current_id = starting_id - 1

    def next(self):
        self.current_id += 1
        return self.current_id

ids = IdGen(1)


db = {}

db_active = True

while db_active:
    name = input("\nWhat is the name of your company? ")

    if name in db.keys():
        print('\nThis company is already listed in the DB.')
        delete_entry = input('\nWould you like to delete the duplicate company you made? (yes/no)')
        if delete_entry in ['yes','y'] :
            del(db[name])
            print('The duplicate company you just entered has been deleted!')
            print()
            db_inspect(db)
            continue

    short_name = input("What would you like the short name to be? ")

    # db[name] = short_name
    db[short_name] = {"id": ids.next(), "short_name": short_name, "name": name}

    print()
    db_inspect(db)
    print()


    repeat = input("Would you like to add another company to the DB? (yes/no) ")
    if repeat in ['no','n'] :
        db_active = False

    print()

print('The DB has the following companies listed:')

# for k, v in db.items():
#     print("Company: " + k.title())
#     print("Short Alias: " + v)

print(db)