# Generated by Django 6.0 on 2026-04-11 16:53

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


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0346_userflagdefinition_userflagassignment'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='UserFingerprintVisit',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('source', models.CharField(blank=True, default='', max_length=32)),
                ('fingerprint_event_id', models.CharField(blank=True, default='', help_text='Canonical Fingerprint event id. The current JS integration sends the legacy requestId value here.', max_length=255)),
                ('fingerprint_visitor_id', models.CharField(blank=True, default='', max_length=255)),
                ('fetch_status', models.CharField(choices=[('pending', 'Pending'), ('processing', 'Processing'), ('succeeded', 'Succeeded'), ('failed', 'Failed'), ('not_configured', 'Not Configured')], default='pending', max_length=24)),
                ('fetch_attempt_count', models.PositiveIntegerField(default=0)),
                ('last_fetch_attempt_at', models.DateTimeField(blank=True, null=True)),
                ('fetched_at', models.DateTimeField(blank=True, null=True)),
                ('error_message', models.TextField(blank=True, default='')),
                ('event_timestamp', models.DateTimeField(blank=True, db_index=True, null=True)),
                ('visitor_first_seen_at', models.DateTimeField(blank=True, null=True)),
                ('replayed', models.BooleanField(blank=True, null=True)),
                ('visitor_found', models.BooleanField(blank=True, null=True)),
                ('visitor_confidence_score', models.FloatField(blank=True, null=True)),
                ('suspect_score', models.FloatField(blank=True, null=True)),
                ('bot', models.CharField(blank=True, default='', max_length=64)),
                ('vpn', models.BooleanField(blank=True, null=True)),
                ('vpn_confidence', models.CharField(blank=True, default='', max_length=32)),
                ('proxy', models.BooleanField(blank=True, null=True)),
                ('proxy_confidence', models.CharField(blank=True, default='', max_length=32)),
                ('proxy_type', models.CharField(blank=True, default='', max_length=32)),
                ('tor', models.BooleanField(blank=True, null=True)),
                ('tampering', models.BooleanField(blank=True, null=True)),
                ('tampering_confidence', models.CharField(blank=True, default='', max_length=32)),
                ('tampering_ml_score', models.FloatField(blank=True, null=True)),
                ('high_activity_device', models.BooleanField(blank=True, null=True)),
                ('ip_blocklist_email_spam', models.BooleanField(blank=True, null=True)),
                ('ip_blocklist_attack_source', models.BooleanField(blank=True, null=True)),
                ('ip_blocklist_tor_node', models.BooleanField(blank=True, null=True)),
                ('datacenter', models.BooleanField(blank=True, null=True)),
                ('asn', models.CharField(blank=True, default='', max_length=64)),
                ('asn_name', models.CharField(blank=True, default='', max_length=255)),
                ('asn_type', models.CharField(blank=True, default='', max_length=64)),
                ('country_code', models.CharField(blank=True, default='', max_length=8)),
                ('country_name', models.CharField(blank=True, default='', max_length=128)),
                ('subdivision_name', models.CharField(blank=True, default='', max_length=128)),
                ('city_name', models.CharField(blank=True, default='', max_length=128)),
                ('timezone', models.CharField(blank=True, default='', max_length=64)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('browser_name', models.CharField(blank=True, default='', max_length=64)),
                ('browser_major_version', models.CharField(blank=True, default='', max_length=32)),
                ('browser_full_version', models.CharField(blank=True, default='', max_length=64)),
                ('os', models.CharField(blank=True, default='', max_length=64)),
                ('os_version', models.CharField(blank=True, default='', max_length=64)),
                ('device', models.CharField(blank=True, default='', max_length=64)),
                ('sdk', models.JSONField(blank=True, default=dict)),
                ('velocity', models.JSONField(blank=True, default=dict)),
                ('vpn_methods', models.JSONField(blank=True, default=dict)),
                ('tampering_details', models.JSONField(blank=True, default=dict)),
                ('raw_payload', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fingerprint_visits', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User fingerprint visit',
                'verbose_name_plural': 'User fingerprint visits',
                'ordering': ['-created_at', '-id'],
                'indexes': [models.Index(fields=['user', 'fetch_status'], name='finger_visit_user_status_idx'), models.Index(fields=['fingerprint_event_id'], name='finger_visit_event_idx'), models.Index(fields=['fingerprint_visitor_id'], name='finger_visit_visitor_idx')],
                'constraints': [models.UniqueConstraint(condition=models.Q(('fingerprint_event_id__gt', '')), fields=('user', 'fingerprint_event_id'), name='uniq_user_fingerprint_evt')],
            },
        ),
    ]
