import json
import os
import urllib2
from sendgrid.helpers.mail import *
from sendgrid import *

# NOTE: you will need move this file to the root
# directory of this project to execute properly.


def build_hello_email():
    """Minimum required to send an email"""
    from_email = Email("test@example.com")
    subject = "Hello World from the SendGrid Python Library"
    to_email = Email("test@example.com")
    content = Content("text/plain", "some text here")
    mail = Mail(from_email, subject, to_email, content)
    mail.personalizations[0].add_to(Email("test2@example.com"))

    return mail.get()


def build_personalization(personalization):
    """Build personalization mock instance from a mock dict"""
    mock_personalization = Personalization()
    for to_addr in personalization['to_list']:
        personalization.add_to(to_addr)

    for cc_addr in personalization['cc_list']:
        personalization.add_to(cc_addr)

    for bcc_addr in personalization['bcc_list']:
        personalization.add_bc(bcc_addr)