# Generated by Django 5.0.6 on 2024-06-10 16:05

import uuid

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Goal',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('state', models.CharField(choices=[
                    ('blocked', 'Blocked'),
                    ('waiting_for_date', 'Waiting For Date'),
                    ('waiting_for_preconditions', 'Waiting For Preconditions'),
                    ('waiting_for_worker', 'Waiting For Worker'),
                    ('achieved', 'Achieved'),
                    ('given_up', 'Given Up'),
                    ('not_going_to_happen_soon', 'Not Going To Happen Soon'),
                ], db_index=True, default='waiting_for_date', max_length=30)),
                ('handler', models.CharField(max_length=100)),
                ('instructions', models.JSONField(null=True)),
                ('precondition_date', models.DateTimeField(default=django.utils.timezone.now, help_text='Goal will not be pursued before this date.')),
                ('created_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
            ],
            options={
                'ordering': ('-created_at',),
            },
        ),
        migrations.CreateModel(
            name='GoalDependency',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('dependent_goal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='dependencies', to='django_goals.goal')),
                ('precondition_goal', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='dependents', to='django_goals.goal')),
            ],
            options={
                'unique_together': {('dependent_goal', 'precondition_goal')},
            },
        ),
        migrations.AddField(
            model_name='goal',
            name='precondition_goals',
            field=models.ManyToManyField(blank=True, related_name='dependent_goals', through='django_goals.GoalDependency', to='django_goals.goal'),
        ),
        migrations.CreateModel(
            name='GoalProgress',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('success', models.BooleanField()),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('time_taken', models.DurationField(null=True)),
                ('goal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='progress', to='django_goals.goal')),
            ],
            options={
                'ordering': ('goal', '-created_at'),
            },
        ),
        migrations.AddIndex(
            model_name='goal',
            index=models.Index(condition=models.Q(('state', 'waiting_for_date')), fields=['precondition_date'], name='goals_waiting_for_date_idx'),
        ),
        migrations.AddIndex(
            model_name='goal',
            index=models.Index(condition=models.Q(('state', 'waiting_for_worker')), fields=['precondition_date'], name='goals_waiting_for_worker_idx'),
        ),
    ]
