# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-22 10:32
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields.hstore
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import munch.core.utils.models
import munch.apps.transactional.models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('core', '0002_permissions'),
    ]

    operations = [
        migrations.CreateModel(
            name='Mail',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('recipient', models.EmailField(max_length=254, verbose_name='recipient')),
                ('identifier', models.CharField(db_index=True, default=munch.apps.transactional.models.get_mail_identifier, max_length=35, unique=True, verbose_name='identifier')),
                ('creation_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='creation date')),
                ('first_status_date', models.DateTimeField(blank=True, null=True, verbose_name='first status date')),
                ('latest_status_date', models.DateTimeField(blank=True, null=True, verbose_name='latest status date')),
                ('delivery_duration', models.DurationField(null=True, verbose_name='delivery duration')),
                ('had_delay', models.BooleanField(default=False, verbose_name='had delay')),
                ('headers', django.contrib.postgres.fields.hstore.HStoreField(verbose_name='headers')),
                ('sender', models.EmailField(max_length=254, verbose_name='sender')),
                ('track_open', models.BooleanField(default=False, help_text='Detect who opens message by adding hidden image.', verbose_name='track opens')),
                ('track_clicks', models.BooleanField(default=False, help_text='Detect which links were clicked by replacing original links by redirections', verbose_name='track clicks')),
                ('msg_links', django.contrib.postgres.fields.hstore.HStoreField(blank=True, null=True, verbose_name='message links')),
                ('curstatus', models.CharField(choices=[('unknown', 'unknown'), ('ignored', 'ignored'), ('deleted', 'deleted'), ('queued', 'queued'), ('sending', 'sending'), ('delayed', 'delayed (retrying)'), ('delivered', 'delivered to remote MTA'), ('dropped', 'not delivered (soft-bounce)'), ('bounced', 'not delivered (hard-bounce)')], default='unknown', max_length=20, verbose_name='current status')),
                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='author')),
            ],
            options={
                'abstract': False,
                'default_permissions': ('view', 'add', 'change', 'delete', 'view_mine', 'change_mine', 'delete_mine', 'view_organizations', 'change_organizations', 'delete_organizations'),
            },
            bases=(models.Model, munch.core.utils.models.OwnedModelMixin),
        ),
        migrations.CreateModel(
            name='MailBatch',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('creation_date', models.DateTimeField(auto_now_add=True, verbose_name='creation date')),
                ('identifier', models.CharField(db_index=True, default=munch.core.mail.utils.mk_base64_uuid, editable=False, max_length=35, unique=True, verbose_name='identifier')),
                ('name', models.CharField(max_length=60, verbose_name='name')),
                ('msg_links', django.contrib.postgres.fields.hstore.HStoreField(blank=True, null=True, verbose_name='message links')),
                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='author')),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='mailbatches', to='core.Category', verbose_name='category')),
            ],
            options={
                'verbose_name': 'mail batch',
                'verbose_name_plural': 'mail batches',
            },
            bases=(models.Model, munch.core.utils.models.OwnedModelMixin),
        ),
        migrations.CreateModel(
            name='MailStatus',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('unknown', 'unknown'), ('ignored', 'ignored'), ('deleted', 'deleted'), ('queued', 'queued'), ('sending', 'sending'), ('delayed', 'delayed (retrying)'), ('delivered', 'delivered to remote MTA'), ('dropped', 'not delivered (soft-bounce)'), ('bounced', 'not delivered (hard-bounce)')], default='queued', max_length=15, verbose_name='status')),
                ('creation_date', models.DateTimeField(verbose_name='creation_date')),
                ('source_ip', models.GenericIPAddressField(blank=True, null=True, verbose_name='source ip')),
                ('source_hostname', models.CharField(blank=True, max_length=100, null=True, verbose_name='source hostname')),
                ('destination_domain', models.CharField(max_length=150, verbose_name='destination domain')),
                ('status_code', models.CharField(blank=True, help_text='X.XXX.XXX, as defined in RFC3463', max_length=25, validators=[django.core.validators.RegexValidator(message='status code should follow rfc3463', regex='([234](\\.\\d{1,3}){2})')], verbose_name='SMTP status code')),
                ('raw_msg', models.TextField(verbose_name='raw message')),
                ('mail', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='statuses', to='transactional.Mail', verbose_name='mail')),
            ],
            options={
                'get_latest_by': 'creation_date',
                'verbose_name': 'mail status',
                'verbose_name_plural': 'mail statuses',
            },
            bases=(models.Model, munch.core.utils.models.OwnedModelMixin),
        ),
        migrations.AddField(
            model_name='mail',
            name='batch',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='mails', to='transactional.MailBatch', verbose_name='batch'),
        ),
        migrations.AddField(
            model_name='mail',
            name='message',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactional_mail', to='core.RawMail', verbose_name='message'),
        ),
        migrations.AlterUniqueTogether(
            name='mailbatch',
            unique_together=set([('author', 'name')]),
        ),
    ]
