import json


def craft_cloud_message(
    username,
    emoji,
    channel,
    launch_time,
    project_name,
    end_date,
    cloud_provider,
    vps_name,
    ip_address,
    tags,
):
    """
    Craft a nicely formatted Slack message using blocks for cloud asset notifications.
    """
    CLOUD_ASSET_MESSAGE = {
        "username": username,
        "icon_emoji": emoji,
        "channel": channel,
        "text": ":cloud: Teardown Notification for {} :cloud:".format(project_name),
        "blocks": [
            {
                "type": "header",
                "text": {
                    "type": "plain_text",
                    "text": ":cloud: Teardown Notification for {} :cloud:".format(
                        project_name
                    ),
                },
            },
            {
                "type": "section",
                "fields": [
                    {
                        "type": "mrkdwn",
                        "text": "*Cloud Provider:*\n{}".format(cloud_provider),
                    },
                    {"type": "mrkdwn", "text": "*Instance Name:*\n{}".format(vps_name)},
                    {
                        "type": "mrkdwn",
                        "text": "*Ext IP Address:*\n{}".format(ip_address),
                    },
                    {
                        "type": "mrkdwn",
                        "text": "*Launch Date:*\n{}".format(launch_time),
                    },
                    {
                        "type": "mrkdwn",
                        "text": "*Project End Date:*\n{}".format(end_date),
                    },
                    {"type": "mrkdwn", "text": "*Tags:*\n{}".format(tags)},
                ],
            },
        ],
    }
    return json.dumps(CLOUD_ASSET_MESSAGE)