# Path: groups/db.py
# class Group(models.Model):
# class GroupMember(models.Model):
# 
# 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 groups import db
from mailgun import api as mailgun_api


def create_group( address, description, sequence ):
    group_db = db.Group(
        address=address, 
        description=description,
        sequence=sequence
    )
    group_db.save()
    return get_group(group_id2uri(group_db.id))


def _group2json(group_db):
    group = {
        'uri': group_id2uri(group_db.id),
        'address': group_db.address,
        'description': group_db.description,
        'sequence': group_db.sequence
    }
    group['members'] = [member.email for member in group_db.members.all()]
    return group


def get_group( group_uri ):
    group_id = group_uri2id(group_uri)
    group_db = db.Group.objects.get(id=group_id)
    return _group2json(group_db)


def get_groups( sequence=None ):

# Path: groups/db.py
# class Group(models.Model):
# class GroupMember(models.Model):
# 
# 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: groups/models.py
from django.conf import settings
from groups import db
from mailgun import api as mailgun_api



def create_group( address, description, sequence ):
    group_db = db.Group(
        address=address, 
        description=description,
        sequence=sequence
    )
    group_db.save()
    return get_group(group_id2uri(group_db.id))


def _group2json(group_db):
    group = {
        'uri': group_id2uri(group_db.id),
        'address': group_db.address,
        'description': group_db.description,
        'sequence': group_db.sequence
    }
    group['members'] = [member.email for member in group_db.members.all()]
    return group


def get_group( group_uri ):
    group_id = group_uri2id(group_uri)
    group_db = db.Group.objects.get(id=group_id)
    return _group2json(group_db)


def get_groups( sequence=None ):

    groups = db.Group.objects.all()