import uuid

import django.db.models.deletion
import pgvector.django.vector
from django.conf import settings
from django.db import migrations, models

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('accounts', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        pgvector.django.VectorExtension(),
        migrations.CreateModel(
            name='TrainingFile',
            fields=[
                ('id', models.BigAutoField(primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='UUID')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
                ('file', models.FileField(upload_to='training_files/%Y/%m/%d/')),
                ('file_name', models.CharField(max_length=255)),
                ('file_size', models.IntegerField()),
                ('file_type', models.CharField(max_length=50)),
                ('description', models.TextField(blank=True, default='')),
                ('status', models.CharField(choices=[('ingesting', 'Ingesting'), ('chunked', 'Chunked'), ('embedded', 'Embedded'), ('failed', 'Failed')], default='ingesting', max_length=20)),
                ('is_processed', models.BooleanField(default=False)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='training_files', to='accounts.organization')),
                ('role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='training_files', to='accounts.role')),
                ('uploaded_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='uploaded_training_files', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Training File',
                'verbose_name_plural': 'Training Files',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RoleRagDocument',
            fields=[
                ('id', models.BigAutoField(primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='UUID')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
                ('content', models.TextField()),
                ('content_hash', models.CharField(db_index=True, max_length=64)),
                ('embedding', pgvector.django.vector.VectorField(blank=True, dimensions=getattr(settings, 'EMBEDDING_DIMENSIONS', 768), null=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('chunk_index', models.IntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rag_documents', to='accounts.organization')),
                ('role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rag_documents', to='accounts.role')),
                ('training_file', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='chunks', to='knowledge.trainingfile')),
            ],
            options={
                'verbose_name': 'Role RAG Document',
                'verbose_name_plural': 'Role RAG Documents',
            },
        ),
    ]
