def main():

    # initializing csv builder to hold block hashes
    cb = CsvBuilder("output.csv")

    # initializing entites to share generated chain
    cm = ChainMediator()
    doctor = Doctor(cm)
    pharmacy = Pharmacy(cm)
    doctor.init_blockchain()

    while True:
        print("Options:")
        print("[1] Doctor: Write a prescription")
        print("[2] Doctor: View the blockchain (encrypted)")
        print("[3] Pharmacist: Fill a prescription (decrypted)")
        print("[4] Corrupt the blockchain")
        print("[5] Validate the blockchain")
        print("[6] Output blockchain hashes to CSV")
        print("[7] Clear blockchain hash CSV")
        print("[quit] exit program")

        decision = str(input())
        if decision == "quit":
            break

        # Doctor: Write a prescription (add a block to the chain)
        elif decision == "1":
            print("How many prescriptions (blocks) would you like to write? ")
            num_blocks = int(input())
            for i in range(num_blocks):
                doctor.add_block()

        # Doctor: View the blockchain (encrypted)
        elif decision == "2":
            doctor.print_chain()

        # Pharmacist: Fill a prescription (decrypted)
        elif decision == "3":
            pharmacy.decrypt_chain()

        # Corrupt the blockchain
        elif decision == "4":
            pharmacy.corrupt_block(1)

        # Validate the blockchain
        elif decision == "5":
            if(cm.validate_chain(pharmacy.BlockChain)):
                print("Blockchain is valid")
            else:
                print("BlockChain Corrupt. Resetting all blocks to Good Chain.")
                cm.fix_corrupt_chains()

        # write blockchain hashes to csv
        elif decision == "6":
            cb.write_to_csv()
            print("Output to",cb.file_path,"complete.")

        # clear hash csv file
        elif decision == "7":
            cb.clear_csv()
            print(cb.file_path,"cleared.")

        else:
            print("Please enter one of the valid options.")
def main():
    # outputting hashes to CSV for analysis
    cb = CsvBuilder("output.csv")
    print(
        "would you like to clear the csv output file, before taking in the next list of hashes? Y/N: "
    )
    choice = str(input())
    if choice == "Y" or choice == "y":
        cb.clear_csv()

    # initializing entites to share generated chain
    cm = ChainMediator()
    doctor = Doctor(cm)
    pharmacy = Pharmacy(cm)
    doctor.add_block(genesis_block())

    while True:
        print("Options:")
        print("[1] Doctor: Write a prescription")
        print("[2] Doctor: View the blockchain (encrypted)")
        print("[3] Pharmacist: Fill a prescription (decrypted)")
        print("[4] Corrupt the blockchain")
        print("[5] Validate the blockchain")
        print("[6] Output blockchain to CSV")
        print("[quit] exit program")

        decision = str(input(""))
        if decision == "quit":
            sys.exit()
        elif decision == "1":
            """
            Doctor: Write a prescription

            Add a block to the chain
            """
            print("How many prescriptions (blocks) would you like to write? ")
            num_blocks = int(input())
            for i in range(1, num_blocks + 1):
                new_block = next_block(doctor.BlockChain[i - 1])
                doctor.add_block(new_block)
                cb.add_data(str(new_block.hash))

        elif decision == "2":
            """
            Doctor: View the blockchain (encrypted)

            View an encrypted version of the blockchain
            """
            doctor.print_chain()

        elif decision == "3":
            """
            Pharmacist: Fill a prescription (decrypted)
            """
            pharmacy.print_chain()

        elif decision == "4":
            """
            Corrupt the blockchain
            """
            doctor.BlockChain[1].timestamp = str(date.datetime.now())
            pharmacy.BlockChain[1].timestamp = str(date.datetime.now())
            print("Blockchain corrupted.")

        elif decision == "5":
            """
            Validate the blockchain
            """
            i = 0
            for sub in cm.Subscribers:
                if (cm.validate_chain(sub.BlockChain)):
                    i += 1
                else:
                    print(
                        "Blockchain is invalid. Delete cascading through depending blocks."
                    )
                    """
                    ###########################################
                    Do all the crazy delete things/restore to moderator's goodchain version
                    ###########################################
                    """

            if (i == len(cm.Subscribers)):
                print("Blockchain validated.")

        elif decision == "6":
            cb.write_to_csv()
            print("Output complete.")
        else:
            print("Please enter one of the valid options.")