def add_credit_card(encryption_key, token):
    print('NEW CREDIT CARD')
    entry = input_credit_card()
    encrypted_entry = encrypt_credit_card(encryption_key, entry)
    if not confirm_save():
        return
    data = {'action': 'add', 'data_type': 'credit_card', 'data': encrypted_entry}
    response = post_user_data(token, data)
    print_save_response(response)
def add_secure_note(encryption_key, token):
    print('NEW SECURE NOTE')
    entry = input_secure_note()
    encrypted_entry = encrypt_secure_note(encryption_key, entry)
    if not confirm_save():
        return
    data = {'action': 'add', 'data_type': 'secure_note', 'data': encrypted_entry}
    response = post_user_data(token, data)
    print_save_response(response)
def add_password(encryption_key, token):
    print('NEW PASSWORD')
    entry = input_password()
    encrypted_entry = encrypt_password(encryption_key, entry)
    if not confirm_save():
        return
    data = {'action': 'add', 'data_type': 'password', 'data': encrypted_entry}
    response = post_user_data(token, data)
    print_save_response(response)
def delete_credit_card(credit_cards, token):
    results = search_credit_cards(credit_cards, print_results_id=True)
    to_delete_relative_id = ask_for_id(credit_cards, results)
    if not confirm_delete(to_delete_relative_id):
        return
    for entry in credit_cards:
        if entry.relative_id == to_delete_relative_id:
            to_delete = entry.id
            data = {'action': 'delete', 'data_type': 'credit_card', 'data': to_delete}
            response = post_user_data(token, data)
            print_delete_response(response)
def delete_secure_note(secure_notes, token):
    results = search_secure_notes(secure_notes, print_results_id=True)
    to_delete_relative_id = ask_for_id(secure_notes, results)
    if not confirm_delete(to_delete_relative_id):
        return
    for entry in secure_notes:
        if entry.relative_id == to_delete_relative_id:
            to_delete = entry.id
            data = {'action': 'delete', 'data_type': 'secure_note', 'data': to_delete}
            response = post_user_data(token, data)
            print_delete_response(response)
def edit_secure_note(secure_notes, encryption_key, token):
    results = search_secure_notes(secure_notes, print_results_id=True)
    to_edit = ask_for_id(secure_notes, results)

    for secure_note in secure_notes:
        if secure_note.relative_id == to_edit:
            print(f'\nEDIT ENTRY #{to_edit}')
            entry = input_secure_note()
            encrypted_entry = encrypt_secure_note(encryption_key, entry)
            encrypted_entry_with_id = {secure_note.id: encrypted_entry}
            if not confirm_save():
                return
            data = {'action': 'edit', 'data_type': 'secure_note', 'data': encrypted_entry_with_id}
            response = post_user_data(token, data)
            print_save_response(response)
def edit_password(passwords, encryption_key, token):
    results = search_passwords(passwords, print_results_id=True)
    to_edit = ask_for_id(passwords, results)

    for password in passwords:
        if password.relative_id == to_edit:
            print(f'\nEDIT ENTRY #{to_edit}')
            entry = input_password()
            encrypted_entry = encrypt_password(encryption_key, entry)
            encrypted_entry_with_id = {password.id: encrypted_entry}
            if not confirm_save():
                return
            data = {'action': 'edit', 'data_type': 'password', 'data': encrypted_entry_with_id}
            response = post_user_data(token, data)
            print_save_response(response)