# Generated by Django 5.2.11 on 2026-02-13 08:56

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='ModelVersion',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('model_name', models.CharField(db_index=True, max_length=255)),
                ('version', models.CharField(db_index=True, max_length=64)),
                ('framework', models.CharField(choices=[('sklearn', 'Sklearn'), ('xgboost', 'Xgboost'), ('lightgbm', 'Lightgbm'), ('other', 'Other')], default='sklearn', max_length=32)),
                ('build_id', models.CharField(blank=True, default='', help_text='Identifier for build / training run / registry entry.', max_length=255)),
                ('commit_hash', models.CharField(blank=True, default='', help_text='Source control commit hash associated with this model version.', max_length=255)),
                ('config_snapshot', models.JSONField(blank=True, help_text='Optional JSON snapshot of key model configuration.', null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'indexes': [models.Index(fields=['model_name', 'version'], name='ml_audit_mo_model_n_4bf050_idx')],
                'unique_together': {('model_name', 'version')},
            },
        ),
        migrations.CreateModel(
            name='RequestingActor',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('actor_type', models.CharField(choices=[('user', 'User'), ('service', 'Service'), ('api_key', 'Api Key'), ('job', 'Job'), ('other', 'Other')], db_index=True, max_length=32)),
                ('actor_id', models.CharField(db_index=True, help_text='Identifier of the actor in the host system (e.g. user ID, client ID).', max_length=255)),
                ('tenant_id', models.CharField(blank=True, db_index=True, default='', help_text='Identifier of the tenant (e.g. customer, organization) in the host system.', max_length=255)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True, default='')),
                ('auth_context', models.JSONField(blank=True, help_text='Optional JSON containing authentication/authorization context.', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'indexes': [models.Index(fields=['actor_type', 'actor_id'], name='ml_audit_re_actor_t_c4a78e_idx'), models.Index(fields=['tenant_id'], name='ml_audit_re_tenant__f6ee55_idx')],
            },
        ),
        migrations.CreateModel(
            name='PredictionEvent',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('prediction_id', models.CharField(db_index=True, help_text='Stable external identifier for this prediction event.', max_length=255, unique=True)),
                ('timestamp', models.DateTimeField(db_index=True, default=django.utils.timezone.now, help_text='When the prediction was made (UTC).')),
                ('trace_id', models.CharField(blank=True, db_index=True, default='', help_text='Optional correlation ID for tracing across services.', max_length=255)),
                ('environment', models.CharField(blank=True, db_index=True, default='', help_text="Environment where the prediction was made (e.g. 'production', 'staging').", max_length=64)),
                ('features', models.JSONField(help_text='Redacted snapshot of model-ready features used for this prediction.')),
                ('input_fingerprint', models.CharField(blank=True, db_index=True, default='', help_text='Fingerprint of the input features (e.g. hash) for detecting data drift.', max_length=255)),
                ('output', models.JSONField(blank=True, db_index=True, help_text='Model output (e.g. prediction, score, probabilities).', null=True)),
                ('confidence', models.FloatField(blank=True, db_index=True, help_text='Optional canonical confidence / probability score for the main outcome.', null=True)),
                ('decision_outcome', models.CharField(blank=True, default='', help_text="Business-level outcome, e.g. 'approved', 'denied', 'fraud', etc.", max_length=64)),
                ('status', models.CharField(choices=[('success', 'Success'), ('failed', 'Failed'), ('partial', 'Partial')], db_index=True, default='success', help_text='Overall status of the prediction attempt.', max_length=32)),
                ('latency_ms', models.FloatField(blank=True, help_text='Time taken for the prediction in milliseconds.', null=True)),
                ('metadata', models.JSONField(blank=True, help_text='Additional metadata about the prediction.', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('model', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='prediction_events', to='ml_audit.modelversion')),
                ('actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='prediction_events', to='ml_audit.requestingactor')),
            ],
        ),
        migrations.CreateModel(
            name='Explanation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('method', models.CharField(blank=True, default='', help_text="Explanation method, e.g. 'shap', 'lime', 'custom_reason_codes'.", max_length=64)),
                ('method_version', models.CharField(blank=True, default='', help_text='Version of the explanation method.', max_length=64)),
                ('payload', models.JSONField(help_text='Structured explanation payload (feature attributions etc.).')),
                ('summary_text', models.TextField(blank=True, default='', help_text='Human-readable summary of the explanation.')),
                ('status', models.CharField(choices=[('success', 'Success'), ('failed', 'Failed'), ('partial', 'Partial')], default='success', help_text='Status of the explanation generation.', max_length=32)),
                ('generated_at', models.DateTimeField(auto_now_add=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('prediction', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='explanation', to='ml_audit.predictionevent')),
            ],
            options={
                'indexes': [models.Index(fields=['method'], name='ml_audit_ex_method_b156a9_idx'), models.Index(fields=['status'], name='ml_audit_ex_status_f07b79_idx')],
            },
        ),
        migrations.AddIndex(
            model_name='predictionevent',
            index=models.Index(fields=['timestamp'], name='ml_audit_pr_timesta_3b52b1_idx'),
        ),
        migrations.AddIndex(
            model_name='predictionevent',
            index=models.Index(fields=['confidence'], name='ml_audit_pr_confide_d075b1_idx'),
        ),
        migrations.AddIndex(
            model_name='predictionevent',
            index=models.Index(fields=['decision_outcome'], name='ml_audit_pr_decisio_c16462_idx'),
        ),
        migrations.AddIndex(
            model_name='predictionevent',
            index=models.Index(fields=['status'], name='ml_audit_pr_status_acb91b_idx'),
        ),
        migrations.AddIndex(
            model_name='predictionevent',
            index=models.Index(fields=['environment'], name='ml_audit_pr_environ_30af0b_idx'),
        ),
    ]
