# You don't have to worry about this
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("DB state: {}".format(', '.join(rep)))


# You don't have to worry about this
class IdGen:
    def __init__(self, starting_id):
        self.current_id = starting_id - 1

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


# -------------------

# ---
# How to use this to get ids:
#   `ids.next()` will return an incrementing ID
# ---
ids = IdGen(1)

# This is sample data (DON'T EDIT THIS!)
sample_data = [
    ("Foo, Inc.", "foo"),
    ("Bar, Inc.", "bar"),
    ("Baz, Inc.", "baz"),
    ("Zoo, Inc.", "zoo"),
    ("Legit Co, Inc.", "lco"),
    ("Not Legit Co.", "bar"),
]

# This is your in-memory database:
db = {}
db_inspect(db)


print("* READ: bar")
# --- start: YOUR READ CODE ---

read = input('Read Company: ')

if read in db:
    print()
    print('Record ID: ' + str(db[read]['id']))
    print('Short Name: ' + db[read]['short_name'])
    print('Company Name: ' + db[read]['name'])
    print()
else:
    print()
    print(read + ' record does not exist')
    print()

# --- end: YOUR READ CODE ---


# Create 2 customers
for name, short_name in sample_data[:2]:
    print("* CREATE: " + short_name)
    # --- start: YOUR CREATE CODE ---
    if short_name in db:
        print()
        print(short_name + ' record was not creatd.  Previous record exists.')
        print()
    else:
        db[short_name] = {"id": ids.next(), "name": name, "short_name": short_name}
        print()
        print(short_name + ' record added.')
        print()
    # --- end: YOUR CREATE CODE ---
    db_inspect(db)


print("* READ: bar")
# --- start: YOUR READ CODE ---

read = input('Read Company: ')

if read in db:
    print()
    print('Record ID: ' + str(db[read]['id']))
    print('Short Name: ' + db[read]['short_name'])
    print('Company Name: ' + db[read]['name'])
    print()
else:
    print()
    print(read + ' record does not exist')
    print()

# --- end: YOUR READ CODE ---


print("* READ: lco")
# --- start: YOUR READ CODE ---

read = input('Read Company: ')

if read in db:
    print()
    print('Record ID: ' + str(db[read]['id']))
    print('Short Name: ' + db[read]['short_name'])
    print('Company Name: ' + db[read]['name'])
    print()
else:
    print()
    print(read + ' record does not exist')
    print()

# --- end: YOUR READ CODE ---


print("* DELETE: lco")
# --- start: YOUR DELETE CODE ---

remove = input('Remove Record: ')

if remove in db:
    del db[remove]
    print()
    print(remove + ' record have been removed from db')
    print()
else:
    print()
    print(remove + ' record does not exist')
    print()

# --- end: YOUR DELETE CODE ---
db_inspect(db)

print("* DELETE: foo")
# --- start: YOUR DELETE CODE ---

remove = input('Remove Record: ')

if remove in db:
    del db[remove]
    print()
    print(remove + ' record have been removed from db')
    print()
else:
    print()
    print(remove + ' record does not exist')
    print()

# --- end: YOUR DELETE CODE ---
db_inspect(db)


# Create 2 customers
for name, short_name in sample_data:
    print("* CREATE: " + short_name)
    # --- start: YOUR CREATE CODE ---
    if short_name in db:
        print()
        print(short_name + ' record was not creatd.  Previous record exists.')
        print()
    else:
        db[short_name] = {"id": ids.next(), "name": name, "short_name": short_name}
        print()
        print(short_name + ' record added.')
        print()
    # --- end: YOUR CREATE CODE ---
    db_inspect(db)
