import requests


def store_document(url, document):
    """
    Stores a document in the database

    :param url: the base url of the REST server
    :param document: document string
    :returns response.text: document_id is returned if successful
    """
    url += "/documents"
    headers = {"Content-Type": "application/json"}
    data = {"text": document}

    response = requests.post(url, headers=headers, json=data)

    if response.status_code == 201:
        # dataset_id = response.json()["data"][0]["id"]
        return response.text
    elif response.status_code == 400:
        return "It is a bad bad request!"
    elif response.status_code == 401:
        return "Unauthorized! You shall not pass!! Please check the API token"
    elif response.status_code == 404:
        return "Not Found"
    else:
        return response.text