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 update_friend(id: str) -> Response:
    """
    Update all aspects of a Friend resource.

    Use a JSON representation to fully update an existing friend resource.
    Args:
        id: The unique identifier of a Friend resouce

    Returns:
        A flask.Response object.
    """
    try:
        payload = api_helpers.json_payload(request)
        api_helpers.required_elements_exist(payload)
    except ValueError as error:
        error_response = make_response(jsonify({"error": str(error)}), 400)
        return error_response

    friend = datastore.existing_friend(payload['id'])
    if friend:
        friend.update({
            "id": payload["id"],
            "first_name": payload["firstName"],
            "last_name": payload["lastName"],
            "telephone": payload["telephone"],
            "email": payload["email"],
            "notes": payload["notes"],
        })

        response = make_response(
            jsonify({
                "message":
                "Friend resource {} updated.".format(payload['id'])
            }))
        return response
    else:
        response = make_response(
            jsonify({
                "error":
                "Friend resource {} not found.".format(payload['id'])
            }), 404)
        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 update_friend(id: str) -> Response:
    """
    Update all aspects of a Friend resource.

    Use a JSON representation to fully update an existing friend resource.
    Args:
        id: The unique identifier of a Friend resouce

    Returns:
        A flask.Response object.
    """
    try:
        payload = api_helpers.json_payload(request)
        api_helpers.required_elements_exist(payload)
    except ValueError as error:
        error_response = make_response(jsonify({"error": str(error)}), 400)
        return error_response

    friend = datastore.existing_friend(payload['id'])
    if friend:
        friend.update({
                "id": payload["id"],
                "first_name": payload["firstName"],
                "last_name": payload["lastName"],
                "telephone": payload["telephone"],
                "email": payload["email"],
                "notes": payload["notes"],
            })

        response = make_response(
            jsonify({"message": "Friend resource {} updated.".format(
                payload['id'])}))
        return response
    else:
        response = make_response(
            jsonify({"error": "Friend resource {} not found.".format(
                payload['id'])}), 404)
        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.
    """

    #DEP_01: Remove dependency on datastore
    try:
        payload = api_helpers.json_payload(request)
        api_helpers.required_elements_exist(payload)
    except ValueError as error:
        error_response = make_response(jsonify({"error": str(error)}), 400)
        return error_response

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

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

    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