# Generated by Django 5.2 on 2026-01-29 20:18

import uuid
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django.utils import timezone


class Migration(migrations.Migration):

    dependencies = [
        ("api", "0275_referralincentiveconfig_alter_taskcredit_grant_type_and_more"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="BurnRateSnapshot",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("scope_type", models.CharField(choices=[("user", "User"), ("organization", "Organization"), ("agent", "Agent")], max_length=32)),
                ("scope_id", models.CharField(max_length=64)),
                ("window_minutes", models.PositiveIntegerField()),
                ("window_start", models.DateTimeField()),
                ("window_end", models.DateTimeField()),
                ("window_total", models.DecimalField(decimal_places=6, max_digits=20)),
                ("burn_rate_per_hour", models.DecimalField(decimal_places=6, max_digits=20)),
                ("burn_rate_per_day", models.DecimalField(decimal_places=6, max_digits=20)),
                ("computed_at", models.DateTimeField(default=timezone.now)),
                ("agent", models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name="burn_rate_snapshots", to="api.persistentagent")),
                ("organization", models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name="burn_rate_snapshots", to="api.organization")),
                ("user", models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name="burn_rate_snapshots", to=settings.AUTH_USER_MODEL)),
            ],
            options={
                "ordering": ["-computed_at"],
                "indexes": [
                    models.Index(fields=["scope_type", "scope_id", "window_minutes"], name="burn_rate_snapshot_scope_idx"),
                ],
                "constraints": [
                    models.UniqueConstraint(fields=["scope_type", "scope_id", "window_minutes"], name="burn_rate_snapshot_unique"),
                ],
            },
        ),
    ]

