def create_friend() -> Response:
    """
    Create a new friend resource.

    Utilize a JSON representation/payload in the request object to
    create a new friend resource.

    Returns:
        A flask.Response object.
    """
    try:
        request_payload = api_helpers.json_payload(request)
        api_helpers.check_required_elements(request_payload)

    except ValueError as error:
        response = make_response(jsonify({"error": str(error)}), 400)
        return response

    if datastore.existing_friend(request_payload["id"]):
        response = make_response(jsonify({"error": "The specified friend resource already exists."}), 400)
    else:
        datastore.friends.append(
            {
                "id": request_payload["id"],
                "first_name": request_payload["firstName"],
                "last_name": request_payload["lastName"],
                "telephone": request_payload["telephone"],
                "email": request_payload["email"],
                "notes": request_payload["notes"],
            }
        )

        response = make_response(jsonify({"message": "Friend resource created."}), 201)

    return response
def fully_update_friend(id: str) -> Response:
    """
    Update all aspects of a specified friend or return an error.

    Use a JSON representation to fully update an existing friend resource.

    Args:
        id: The unique identifier of a friend resource.

    Returns:
        A flask.Response object.
    """
    try:
        request_payload = api_helpers.json_payload(request)
        api_helpers.check_required_elements(request_payload)

    except ValueError as error:
        response = make_response(jsonify({"error": str(error)}), 400)
        return response

    friend = datastore.existing_friend(request_payload["id"])

    if friend:
        friend.update(
            {
                "id": request_payload["id"],
                "first_name": request_payload["firstName"],
                "last_name": request_payload["lastName"],
                "telephone": request_payload["telephone"],
                "email": request_payload["email"],
                "notes": request_payload["notes"],
            }
        )
        response = jsonify({"message": "Friend resource updated."})
        return response
    else:
        response = make_response(
            jsonify(
                {"error": "No friend resource exists that matches the given id: " "{}".format(request_payload["id"])}
            ),
            400,
        )
        return response
def fully_update_friend(id: str) -> Response:
    """
    Update all aspects of a specified friend or return an error.

    Use a JSON representation to fully update an existing friend resource.

    Args:
        id: The unique identifier of a friend resource.

    Returns:
        A flask.Response object.
    """
    try:
        request_payload = api_helpers.json_payload(request)
        api_helpers.check_required_elements(request_payload)

    except ValueError as error:
        response = make_response(jsonify({"error": str(error)}), 400)
        return response

    friend = datastore.existing_friend(request_payload["id"])

    if friend:
        friend.update({
            "id": request_payload['id'],
            "first_name": request_payload['firstName'],
            "last_name": request_payload['lastName'],
            "telephone": request_payload['telephone'],
            "email": request_payload['email'],
            "notes": request_payload['notes']
        })
        response = jsonify({"message": "Friend resource updated."})
        return response
    else:
        response = make_response(
            jsonify({
                "error":
                "No friend resource exists that matches the given id: "
                "{}".format(request_payload["id"])
            }), 400)
        return response
def create_friend() -> Response:
    """
    Create a new friend resource.

    Utilize a JSON representation/payload in the request object to
    create a new friend resource.

    Returns:
        A flask.Response object.
    """
    try:
        request_payload = api_helpers.json_payload(request)
        api_helpers.check_required_elements(request_payload)

    except ValueError as error:
        response = make_response(jsonify({"error": str(error)}), 400)
        return response

    if datastore.existing_friend(request_payload["id"]):
        response = make_response(
            jsonify({"error":
                     "The specified friend resource already exists."}), 400)
    else:
        datastore.friends.append({
            "id": request_payload['id'],
            "first_name": request_payload['firstName'],
            "last_name": request_payload['lastName'],
            "telephone": request_payload['telephone'],
            "email": request_payload['email'],
            "notes": request_payload['notes']
        })

        response = make_response(
            jsonify({"message": "Friend resource created."}), 201)

    return response