# Generated by Django 5.2 on 2026-01-21 00:00

import uuid

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


class Migration(migrations.Migration):

    dependencies = [
        ("api", "0270_alter_userattribution_referrer_code"),
    ]

    operations = [
        migrations.CreateModel(
            name="ComputeSnapshot",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("k8s_snapshot_name", models.CharField(max_length=255)),
                ("size_bytes", models.PositiveBigIntegerField(blank=True, null=True)),
                (
                    "status",
                    models.CharField(
                        choices=[("ready", "Ready"), ("failed", "Failed")],
                        default="ready",
                        max_length=16,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "agent",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="compute_snapshots",
                        to="api.persistentagent",
                    ),
                ),
            ],
            options={
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentComputeSession",
            fields=[
                (
                    "agent",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        primary_key=True,
                        related_name="compute_session",
                        serialize=False,
                        to="api.persistentagent",
                    ),
                ),
                ("pod_name", models.CharField(blank=True, max_length=128)),
                ("namespace", models.CharField(blank=True, max_length=128)),
                (
                    "state",
                    models.CharField(
                        choices=[
                            ("running", "Running"),
                            ("idle_stopping", "Idle Stopping"),
                            ("stopped", "Stopped"),
                            ("error", "Error"),
                        ],
                        default="stopped",
                        max_length=32,
                    ),
                ),
                ("last_activity_at", models.DateTimeField(blank=True, null=True)),
                ("lease_expires_at", models.DateTimeField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "workspace_snapshot",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="sessions",
                        to="api.computesnapshot",
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name="computesnapshot",
            index=models.Index(fields=["agent", "created_at"], name="compute_snapshot_agent_idx"),
        ),
        migrations.AddIndex(
            model_name="agentcomputesession",
            index=models.Index(fields=["state"], name="compute_session_state_idx"),
        ),
        migrations.AddIndex(
            model_name="agentcomputesession",
            index=models.Index(fields=["lease_expires_at"], name="compute_session_lease_idx"),
        ),
    ]
