# 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='RequestNonce',
            fields=[
                ('nonce_hash', models.CharField(max_length=64, primary_key=True, serialize=False)),
                ('expires_at', models.DateTimeField(db_index=True)),
            ],
            options={
                'db_table': 'request_nonces',
            },
        ),
        migrations.CreateModel(
            name='ApiKey',
            fields=[
                ('id', snapfile.core.fields.UUIDv7Field(default=snapfile.core.ids.uuid7, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=128)),
                ('env', models.CharField(default='live', max_length=8)),
                ('prefix', models.CharField(max_length=16, unique=True)),
                ('key_hash', models.CharField(max_length=64)),
                ('hmac_secret_enc', models.TextField(blank=True, null=True)),
                ('require_signature', models.BooleanField(default=False)),
                ('scopes', models.JSONField(default=list)),
                ('ip_allowlist', models.JSONField(blank=True, null=True)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('last_used_at', models.DateTimeField(blank=True, null=True)),
                ('last_used_ip', models.CharField(blank=True, max_length=45, null=True)),
                ('revoked_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='api_keys', to='projects.project')),
                ('rotated_from', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='integration.apikey')),
            ],
            options={
                'db_table': 'api_keys',
            },
        ),
        migrations.CreateModel(
            name='IdempotencyKey',
            fields=[
                ('id', snapfile.core.fields.UUIDv7Field(default=snapfile.core.ids.uuid7, editable=False, primary_key=True, serialize=False)),
                ('key_hash', models.CharField(max_length=64)),
                ('fingerprint', models.CharField(max_length=64)),
                ('response_status', models.PositiveSmallIntegerField(null=True)),
                ('response_body', models.JSONField(null=True)),
                ('resource_id', models.CharField(max_length=64, null=True)),
                ('locked_until', models.DateTimeField(null=True)),
                ('expires_at', models.DateTimeField(db_index=True)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.project')),
            ],
            options={
                'db_table': 'idempotency_keys',
                'constraints': [models.UniqueConstraint(fields=('project', 'key_hash'), name='idem_project_key')],
            },
        ),
    ]
