# Generated by Django 5.2.4 on 2025-07-24 22:10

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='DataExport',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('export_type', models.CharField(help_text='Type of data exported', max_length=100)),
                ('file_format', models.CharField(default='CSV', max_length=20)),
                ('record_count', models.PositiveIntegerField(default=0)),
                ('file_size', models.PositiveIntegerField(default=0, help_text='File size in bytes')),
                ('filters_applied', models.JSONField(blank=True, default=dict)),
                ('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('file_path', models.CharField(blank=True, max_length=500)),
                ('download_count', models.PositiveIntegerField(default=0)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data_exports', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Data Export',
                'verbose_name_plural': 'Data Exports',
                'ordering': ['-timestamp'],
            },
        ),
        migrations.CreateModel(
            name='LoginAttempt',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('username', models.CharField(max_length=150)),
                ('status', models.CharField(choices=[('SUCCESS', 'Success'), ('FAILED', 'Failed'), ('BLOCKED', 'Blocked')], max_length=10)),
                ('ip_address', models.GenericIPAddressField()),
                ('user_agent', models.TextField(blank=True)),
                ('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
                ('failure_reason', models.CharField(blank=True, max_length=200)),
                ('country', models.CharField(blank=True, max_length=100)),
                ('city', models.CharField(blank=True, max_length=100)),
            ],
            options={
                'verbose_name': 'Login Attempt',
                'verbose_name_plural': 'Login Attempts',
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['username', 'timestamp'], name='audit_login_usernam_86a7ab_idx'), models.Index(fields=['ip_address', 'timestamp'], name='audit_login_ip_addr_8dc769_idx'), models.Index(fields=['status', 'timestamp'], name='audit_login_status_e00c0c_idx')],
            },
        ),
        migrations.CreateModel(
            name='AuditLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(choices=[('CREATE', 'Create'), ('UPDATE', 'Update'), ('DELETE', 'Delete'), ('VIEW', 'View'), ('LOGIN', 'Login'), ('LOGOUT', 'Logout'), ('EXPORT', 'Export'), ('IMPORT', 'Import')], max_length=20)),
                ('object_id', models.PositiveIntegerField()),
                ('object_repr', models.CharField(help_text='String representation of the object', max_length=200)),
                ('changes', models.JSONField(blank=True, default=dict)),
                ('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True)),
                ('session_key', models.CharField(blank=True, max_length=40)),
                ('reason', models.TextField(blank=True, help_text='Reason for the action')),
                ('module', models.CharField(blank=True, help_text='Module/app where action occurred', max_length=100)),
                ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='audit_logs', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Audit Log',
                'verbose_name_plural': 'Audit Logs',
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['user', 'timestamp'], name='audit_audit_user_id_e8be02_idx'), models.Index(fields=['content_type', 'object_id'], name='audit_audit_content_4c2ead_idx'), models.Index(fields=['action', 'timestamp'], name='audit_audit_action_2a1328_idx'), models.Index(fields=['timestamp'], name='audit_audit_timesta_19e18a_idx')],
            },
        ),
        migrations.CreateModel(
            name='SystemEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_type', models.CharField(choices=[('ERROR', 'Error'), ('WARNING', 'Warning'), ('INFO', 'Information'), ('SECURITY', 'Security'), ('PERFORMANCE', 'Performance'), ('MAINTENANCE', 'Maintenance')], max_length=20)),
                ('title', models.CharField(max_length=200)),
                ('description', models.TextField()),
                ('module', models.CharField(blank=True, max_length=100)),
                ('function_name', models.CharField(blank=True, max_length=100)),
                ('line_number', models.PositiveIntegerField(blank=True, null=True)),
                ('error_code', models.CharField(blank=True, max_length=50)),
                ('stack_trace', models.TextField(blank=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
                ('resolved', models.BooleanField(default=False)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_events', to=settings.AUTH_USER_MODEL)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'System Event',
                'verbose_name_plural': 'System Events',
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['event_type', 'timestamp'], name='audit_syste_event_t_357b65_idx'), models.Index(fields=['resolved', 'timestamp'], name='audit_syste_resolve_0ed65b_idx'), models.Index(fields=['user', 'timestamp'], name='audit_syste_user_id_3aa70b_idx')],
            },
        ),
    ]
