# Generated by Django 5.2 on 2025-11-05 14:42

import django.db.models.deletion
import uuid

from django.db import migrations, models


class Migration(migrations.Migration):

    atomic = False

    dependencies = [
        ('api', '0179_alter_userattribution_fbc_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='PersistentAgentCompletion',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('prompt_tokens', models.IntegerField(blank=True, null=True)),
                ('completion_tokens', models.IntegerField(blank=True, null=True)),
                ('total_tokens', models.IntegerField(blank=True, null=True)),
                ('cached_tokens', models.IntegerField(blank=True, null=True)),
                ('llm_model', models.CharField(blank=True, max_length=256, null=True)),
                ('llm_provider', models.CharField(blank=True, max_length=128, null=True)),
                ('credits_cost', models.DecimalField(blank=True, decimal_places=3, help_text='Credits consumed for this completion (if charged).', max_digits=12, null=True)),
                ('billed', models.BooleanField(default=False, help_text='True once credits were consumed for this completion.')),
                ('billed_at', models.DateTimeField(blank=True, null=True)),
                ('agent', models.ForeignKey(help_text='Agent that triggered this LLM completion.', on_delete=django.db.models.deletion.CASCADE, related_name='completions', to='api.persistentagent')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='persistentagentstep',
            name='completion',
            field=models.ForeignKey(blank=True, help_text='LLM completion that produced this step (if applicable).', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='steps', to='api.persistentagentcompletion'),
        ),
        migrations.AddIndex(
            model_name='persistentagentcompletion',
            index=models.Index(fields=['agent', '-created_at'], name='pa_completion_recent_idx'),
        ),
    ]
