# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-31 18:26
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0008_alter_user_username_max_length'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('contenttypes', '0002_remove_content_type_name'),
    ]

    operations = [
        migrations.CreateModel(
            name='Action',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('name', models.CharField(max_length=64, verbose_name='Name')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
            ],
            options={
                'verbose_name': 'Action',
                'verbose_name_plural': 'Actions',
            },
        ),
        migrations.CreateModel(
            name='AvailableTask',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('description', models.TextField(null=True, verbose_name='Description')),
                ('_cached_description', models.TextField(null=True, verbose_name='Cached Description')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('name', models.CharField(max_length=128, verbose_name='Name')),
                ('klass', models.CharField(max_length=512, verbose_name='Task')),
            ],
            options={
                'verbose_name': 'Available Task',
                'verbose_name_plural': 'Available Tasks',
            },
        ),
        migrations.CreateModel(
            name='State',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('code', models.CharField(max_length=32, unique=True, verbose_name='Code')),
                ('description', models.CharField(max_length=128, null=True, verbose_name='Description')),
                ('actions', models.ManyToManyField(to='workflow.Action')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
            ],
            options={
                'verbose_name': 'State',
                'verbose_name_plural': 'States',
            },
        ),
        migrations.CreateModel(
            name='StateController',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('object_id', models.PositiveIntegerField()),
                ('task_id', models.CharField(blank=True, help_text='Task ID that this controller is currently running.', max_length=64, null=True, verbose_name='Task ID')),
                ('inner_state', models.CharField(choices=[(b'idle', 'Idle'), (b'running', 'Running')], default=b'idle', max_length=32, verbose_name='Inner State')),
                ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
                ('current_state', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='workflow.State', verbose_name='Current State')),
            ],
            options={
                'verbose_name': 'State Controller',
                'verbose_name_plural': 'State Controllers',
            },
        ),
        migrations.CreateModel(
            name='StateControllerData',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('data', django.contrib.postgres.fields.jsonb.JSONField(default=dict, verbose_name='State Data')),
                ('controller', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data', to='workflow.StateController', verbose_name='State Controller')),
                ('state', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='workflow.State', verbose_name='State')),
            ],
            options={
                'ordering': ('-date_created',),
            },
        ),
        migrations.CreateModel(
            name='StateMachine',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('description', models.TextField(null=True, verbose_name='Description')),
                ('_cached_description', models.TextField(null=True, verbose_name='Cached Description')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('name', models.CharField(max_length=64, verbose_name='Name')),
                ('representation', django.contrib.postgres.fields.jsonb.JSONField(help_text='Graphic representation of the FSM graph in JSON.', null=True, verbose_name='Representation')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
                ('initial_state', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='workflow.State', verbose_name='Initial State')),
            ],
            options={
                'verbose_name': 'State Machine',
                'verbose_name_plural': 'State Machines',
            },
        ),
        migrations.CreateModel(
            name='Transition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('name', models.CharField(max_length=64, verbose_name='Name')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
                ('from_state', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='from_transitions', to='workflow.State')),
                ('machine', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transitions', to='workflow.StateMachine')),
                ('permissions', models.ManyToManyField(to='auth.Permission')),
            ],
            options={
                'verbose_name': 'Transition',
                'verbose_name_plural': 'Transitions',
            },
        ),
        migrations.CreateModel(
            name='TransitionLog',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('controller', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transition_logs', to='workflow.StateController', verbose_name='State Controller')),
                ('from_state', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='workflow.State', verbose_name='From State')),
                ('to_state', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='workflow.State', verbose_name='To State')),
            ],
            options={
                'ordering': ('-date_created',),
                'verbose_name': 'Transition Log',
                'verbose_name_plural': 'Transition Logs',
            },
        ),
        migrations.CreateModel(
            name='TransitionTask',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
                ('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date Updated')),
                ('order', models.PositiveIntegerField(db_index=True, editable=False)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
                ('task', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transition_tasks', to='workflow.AvailableTask')),
                ('transition', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transition_tasks', to='workflow.Transition')),
            ],
            options={
                'ordering': ('transition', 'order'),
                'abstract': False,
                'verbose_name': 'Task',
                'verbose_name_plural': 'Tasks',
            },
        ),
        migrations.AddField(
            model_name='transition',
            name='tasks',
            field=models.ManyToManyField(related_name='transitions', through='workflow.TransitionTask', to='workflow.AvailableTask'),
        ),
        migrations.AddField(
            model_name='transition',
            name='to_state',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='to_transitions', to='workflow.State'),
        ),
        migrations.AddField(
            model_name='statecontroller',
            name='machine',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='workflow.StateMachine', verbose_name='State Machine'),
        ),
        migrations.AlterUniqueTogether(
            name='transition',
            unique_together=set([('machine', 'from_state', 'to_state')]),
        ),
        migrations.AlterUniqueTogether(
            name='statecontroller',
            unique_together=set([('content_type', 'object_id')]),
        ),
    ]
