from datetime import datetime
import json
import requests


def send_metrics(
    uuid,
    data,
    solution_id,
    url="https://metrics.awssolutionsbuilder.com/generic",
):
    """sends metric to aws-solutions

    Args:
        uuid (string): unique id to make metrics anonymous
        data (dict): usage metrics from the solution
        solution_id (string): solution id
        url (str, optional): aws-solutions endpoint. \
            Defaults to "https://metrics.awssolutionsbuilder.com/generic".

    Returns:
        int: request code
    """
    time_stamp = {
        "TimeStamp": str(datetime.utcnow().isoformat())
        .replace("T", " ")
        .replace("Z", "")
    }  # Date and time instant in a java.sql.Timestamp compatible format,
    params = {"Solution": solution_id, "UUID": uuid, "Data": data}
    metrics = dict(time_stamp, **params)
    json_data = json.dumps(metrics)
    headers = {"content-type": "application/json"}
    req = requests.post(url, data=json_data, headers=headers)
    code = req.status_code
    return code