"""
SendGrid — Send Email Demo
===========================
A minimal, ready-to-run example of sending an email with SendGrid.

Get an API key (free tier):
    1. Create an account at https://signup.sendgrid.com
    2. Verify a sender identity under Settings -> Sender Authentication
       (required before email will send).
    3. Go to Settings -> API Keys -> Create API Key and copy it.

Setup:
    pip install sendgrid
    export SENDGRID_API_KEY="SG...."

Run:
    python sendgrid_demo.py
"""

import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail


def send_email(to: str, subject: str, html: str) -> int:
    """Send an HTML email and return the HTTP status code."""
    message = Mail(
        from_email="hello@krueng.ai",
        to_emails=to,
        subject=subject,
        html_content=html,
    )
    client = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))
    response = client.send(message)
    return response.status_code


if __name__ == "__main__":
    status = send_email("you@example.com", "Hi", "<strong>Hello from krueng.ai</strong>")
    print(f"Status: {status}")
