# Path: mailgun/api.py
# def call_mailgun(method, api_sub_url, data, params=None):
# def send_email(to_email, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None):
# def send_mass_email(to_emails, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None, recipient_variables=None):
# def create_campaign(campaign_id, campaign_name):
# def create_list(address, name=None, description=None, access_level=None):
# def update_list(address, name=None, description=None, access_level=None):
# def add_list_member(list_address, member_address):
# def remove_list_member(list_address, member_address):
# def get_list(list_address):
# def get_list_members(list_address):
# def get_unsubscribes(address):
# def delete_all_unsubscribes(address):
# def get_list_stats(list_address):
# def get_logs(limit=100, skip=0):
# def fetch_all_logs():
# def get_events(limit, **kwargs):
# def get_all_events(**kwargs):
# def get_campaign_events(campaign_id, event, recipient=None, limit=None, page=None, count=None):
# def _get_campaign_action(campaign_id, action, group_by, limit=None, page=None, count=None):
# def get_campaign_opens(campaign_id, group_by, limit=None, page=None, count=None):
# def get_campaign_clicks(campaign_id, group_by, limit=None, page=None, count=None):


from django.conf import settings
from mailgun import api as mailgun_api
import db
import datetime
def sequence_campaign( sequence_number ):
    if settings.DEBUG:
        return '{0}-{1}-campaign-test'.format(settings.MOOC_TITLE.replace(' ', '-').lower(), sequence_number)
    return '{0}-{1}-campaign'.format(settings.MOOC_TITLE.replace(' ', '-').lower(), sequence_number)


def sequence2dict( sequence_db ):
    return {
        'id': sequence_db.id,
        'start_date': sequence_db.start_date,
        'signup_close_date': sequence_db.signup_close_date,
        'global_list': sequence_list_name(sequence_db.id),
        'campaign_id': sequence_campaign(sequence_db.id)
    }


def create_sequence( start_date, signup_close_date ):
    sequence_db = db.Sequence(
        start_date = start_date,
        signup_close_date = signup_close_date
    )
    sequence_db.save()

    mailgun_api.create_list(
        sequence_list_name(sequence_db.id),
        'Sequence {0} global list'.format(sequence_db.id),
        'List for all members of sequence {0}'.format(sequence_db.id),
        'readonly'
    )


# Path: mailgun/api.py
# def call_mailgun(method, api_sub_url, data, params=None):
# def send_email(to_email, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None):
# def send_mass_email(to_emails, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None, recipient_variables=None):
# def create_campaign(campaign_id, campaign_name):
# def create_list(address, name=None, description=None, access_level=None):
# def update_list(address, name=None, description=None, access_level=None):
# def add_list_member(list_address, member_address):
# def remove_list_member(list_address, member_address):
# def get_list(list_address):
# def get_list_members(list_address):
# def get_unsubscribes(address):
# def delete_all_unsubscribes(address):
# def get_list_stats(list_address):
# def get_logs(limit=100, skip=0):
# def fetch_all_logs():
# def get_events(limit, **kwargs):
# def get_all_events(**kwargs):
# def get_campaign_events(campaign_id, event, recipient=None, limit=None, page=None, count=None):
# def _get_campaign_action(campaign_id, action, group_by, limit=None, page=None, count=None):
# def get_campaign_opens(campaign_id, group_by, limit=None, page=None, count=None):
# def get_campaign_clicks(campaign_id, group_by, limit=None, page=None, count=None):


# Path: sequence/models.py
from django.conf import settings
from mailgun import api as mailgun_api
import db
import datetime

def sequence_campaign( sequence_number ):
    if settings.DEBUG:
        return '{0}-{1}-campaign-test'.format(settings.MOOC_TITLE.replace(' ', '-').lower(), sequence_number)
    return '{0}-{1}-campaign'.format(settings.MOOC_TITLE.replace(' ', '-').lower(), sequence_number)


def sequence2dict( sequence_db ):
    return {
        'id': sequence_db.id,
        'start_date': sequence_db.start_date,
        'signup_close_date': sequence_db.signup_close_date,
        'global_list': sequence_list_name(sequence_db.id),
        'campaign_id': sequence_campaign(sequence_db.id)
    }


def create_sequence( start_date, signup_close_date ):
    sequence_db = db.Sequence(
        start_date = start_date,
        signup_close_date = signup_close_date
    )
    sequence_db.save()

    mailgun_api.create_list(
        sequence_list_name(sequence_db.id),
        'Sequence {0} global list'.format(sequence_db.id),
        'List for all members of sequence {0}'.format(sequence_db.id),
        'readonly'
    )


    mailgun_api.create_campaign(