# Generated by Django 5.2.18 on 2026-11-03 15:35

import django.db.models.deletion
import django.utils.timezone
import snapfile.core.fields
import snapfile.core.ids
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('projects', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Template',
            fields=[
                ('id', snapfile.core.fields.UUIDv7Field(default=snapfile.core.ids.uuid7, editable=False, primary_key=True, serialize=False)),
                ('key', models.CharField(max_length=64)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True, null=True)),
                ('tags', models.JSONField(blank=True, null=True)),
                ('draft_document', models.JSONField()),
                ('draft_revision', models.PositiveIntegerField(default=1)),
                ('draft_hash', models.CharField(max_length=64)),
                ('output_defaults', models.JSONField(default=dict)),
                ('variables_override', models.JSONField(blank=True, null=True)),
                ('sample_data', models.JSONField(blank=True, null=True)),
                ('thumbnail_path', models.CharField(blank=True, max_length=512, null=True)),
                ('locked_by', models.JSONField(blank=True, null=True)),
                ('locked_until', models.DateTimeField(blank=True, null=True)),
                ('created_by', models.JSONField(blank=True, null=True)),
                ('updated_by', models.JSONField(blank=True, null=True)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='templates', to='projects.project')),
            ],
            options={
                'db_table': 'templates',
            },
        ),
        migrations.CreateModel(
            name='TemplateVersion',
            fields=[
                ('id', snapfile.core.fields.UUIDv7Field(default=snapfile.core.ids.uuid7, editable=False, primary_key=True, serialize=False)),
                ('number', models.PositiveIntegerField()),
                ('status', models.CharField(default='published', max_length=16)),
                ('document', models.JSONField()),
                ('document_hash', models.CharField(max_length=64)),
                ('schema_snapshot', models.JSONField(default=list)),
                ('json_schema', models.JSONField(default=dict)),
                ('format_version', models.PositiveSmallIntegerField(default=1)),
                ('engine_version', models.CharField(max_length=16)),
                ('plan_status', models.CharField(default='pending', max_length=16)),
                ('plan_ref', models.CharField(blank=True, max_length=512, null=True)),
                ('plan_hash', models.CharField(blank=True, max_length=64, null=True)),
                ('dependencies', models.JSONField(default=dict)),
                ('comment', models.TextField(blank=True, null=True)),
                ('published_by', models.JSONField(default=dict)),
                ('published_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='projects.project')),
                ('template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='versions', to='doctemplates.template')),
            ],
            options={
                'db_table': 'template_versions',
            },
        ),
        migrations.AddField(
            model_name='template',
            name='current_version',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='doctemplates.templateversion'),
        ),
        migrations.AddConstraint(
            model_name='templateversion',
            constraint=models.UniqueConstraint(fields=('template', 'number'), name='versions_template_number'),
        ),
        migrations.AddIndex(
            model_name='template',
            index=models.Index(fields=['project', 'id'], name='templates_project_id'),
        ),
        migrations.AddConstraint(
            model_name='template',
            constraint=models.UniqueConstraint(fields=('project', 'key'), name='templates_project_key'),
        ),
    ]
