# Generated by Django 5.2.6 on 2025-12-01 21:29

import django.contrib.auth.models
import django.contrib.auth.validators
import django.db.models.deletion
import django.utils.timezone
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0012_alter_user_first_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
                ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
                ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
                ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                ('user_type', models.CharField(choices=[('admin', 'Admin'), ('coach', 'Coach'), ('player', 'Player'), ('journalist', 'Journalist'), ('general', 'General')], max_length=20)),
                ('state', models.CharField(choices=[('enabled', 'Enabled'), ('disabled', 'Disabled'), ('deleted', 'Deleted')], default='enabled', max_length=20)),
                ('phone_number', models.CharField(blank=True, max_length=20)),
                ('address', models.TextField(blank=True)),
                ('logo', models.ImageField(blank=True, null=True, upload_to='user_logos/')),
                ('team_ids', models.JSONField(blank=True, default=list)),
                ('internal_player_id', models.IntegerField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('last_login_ip', models.GenericIPAddressField(blank=True, null=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
            ],
            options={
                'ordering': ['-created_at'],
            },
            managers=[
                ('objects', django.contrib.auth.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='DataAccessLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('resource_type', models.CharField(max_length=50)),
                ('resource_id', models.IntegerField()),
                ('action', models.CharField(max_length=50)),
                ('ip_address', models.GenericIPAddressField()),
                ('access_granted', models.BooleanField(default=True)),
                ('denial_reason', models.CharField(blank=True, max_length=200)),
                ('response_time_ms', models.IntegerField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data_access_logs', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Permission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text="Nombre descriptivo: 'Ver Equipo', 'Bloquear Rival'", max_length=100)),
                ('description', models.TextField(blank=True)),
                ('type', models.CharField(choices=[('allow', 'Allow'), ('block', 'Block')], max_length=10)),
                ('level', models.CharField(choices=[('region', 'Region'), ('competition', 'Competition'), ('team', 'Team'), ('division', 'Division'), ('match', 'Match'), ('player', 'Player')], max_length=20)),
                ('depth', models.CharField(choices=[('instant', 'Instant'), ('historic', 'Historic')], max_length=10)),
                ('priority', models.IntegerField(default=0, help_text='Mayor número = mayor prioridad en conflictos')),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Data Permission Template',
                'verbose_name_plural': 'Data Permission Templates',
                'db_table': 'clients_permission',
                'ordering': ['-priority', 'name'],
                'indexes': [models.Index(fields=['type', 'level'], name='clients_per_type_939502_idx'), models.Index(fields=['priority'], name='clients_per_priorit_d955df_idx'), models.Index(fields=['is_active'], name='clients_per_is_acti_cf7d0d_idx')],
            },
        ),
        migrations.CreateModel(
            name='ClientPermission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('relation_id', models.JSONField(default=dict, help_text='Ejemplo: {"team_id": 10} o {"match_id": 123}')),
                ('timeline_start', models.DateField(help_text='Puede ver datos desde esta fecha')),
                ('timeline_end', models.DateField(help_text='Puede ver datos hasta esta fecha')),
                ('starts_at', models.DateTimeField(help_text='El permiso empieza a aplicar desde aquí')),
                ('expires_at', models.DateTimeField(help_text='El permiso expira aquí')),
                ('state', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('expired', 'Expired'), ('deleted', 'Deleted')], default='active', max_length=20)),
                ('notes', models.TextField(blank=True, help_text='Notas administrativas sobre este permiso')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data_permissions', to=settings.AUTH_USER_MODEL)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='data_permissions_created', to=settings.AUTH_USER_MODEL)),
                ('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='assignments', to='clients.permission')),
            ],
            options={
                'verbose_name': 'Client Data Permission',
                'verbose_name_plural': 'Client Data Permissions',
                'db_table': 'clients_clientpermission',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='SupportTicket',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('ticket_number', models.CharField(max_length=20, unique=True)),
                ('ticket_type', models.CharField(choices=[('petition', 'Petition'), ('complaint', 'Complaint'), ('claim', 'Claim'), ('suggestion', 'Suggestion')], max_length=20)),
                ('subject', models.CharField(max_length=200)),
                ('description', models.TextField()),
                ('status', models.CharField(choices=[('open', 'Open'), ('in_progress', 'In Progress'), ('waiting_user', 'Waiting for User'), ('resolved', 'Resolved'), ('closed', 'Closed')], default='open', max_length=20)),
                ('priority', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('urgent', 'Urgent')], default='medium', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('closed_at', models.DateTimeField(blank=True, null=True)),
                ('response_deadline', models.DateTimeField(blank=True, null=True)),
                ('resolution_deadline', models.DateTimeField(blank=True, null=True)),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_tickets', to=settings.AUTH_USER_MODEL)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tickets', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='TicketMessage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('message', models.TextField()),
                ('attachments', models.JSONField(blank=True, default=list)),
                ('is_internal_note', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('sender', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('ticket', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='clients.supportticket')),
            ],
            options={
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserActivity',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('activity_type', models.CharField(choices=[('login', 'Login'), ('logout', 'Logout'), ('page_view', 'Page View'), ('report_generated', 'Report Generated'), ('report_downloaded', 'Report Downloaded'), ('data_export', 'Data Export'), ('settings_changed', 'Settings Changed'), ('api_call', 'API Call')], max_length=30)),
                ('page_url', models.CharField(blank=True, max_length=500)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('session_id', models.CharField(blank=True, max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activities', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserPreference',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('language', models.CharField(default='en', max_length=10)),
                ('timezone', models.CharField(default='UTC', max_length=50)),
                ('date_format', models.CharField(default='YYYY-MM-DD', max_length=20)),
                ('email_notifications', models.BooleanField(default=True)),
                ('sms_notifications', models.BooleanField(default=False)),
                ('notification_types', models.JSONField(blank=True, default=dict)),
                ('default_dashboard_view', models.CharField(default='overview', max_length=50)),
                ('favorite_teams', models.JSONField(blank=True, default=list)),
                ('favorite_players', models.JSONField(blank=True, default=list)),
                ('default_date_range', models.CharField(default='last_30_days', max_length=20)),
                ('default_chart_type', models.CharField(default='line', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='preferences', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name_plural': 'User preferences',
            },
        ),
        migrations.AddIndex(
            model_name='user',
            index=models.Index(fields=['user_type', 'state'], name='clients_use_user_ty_753c0b_idx'),
        ),
        migrations.AddIndex(
            model_name='user',
            index=models.Index(fields=['uuid'], name='clients_use_uuid_c8cf1f_idx'),
        ),
        migrations.AddIndex(
            model_name='dataaccesslog',
            index=models.Index(fields=['user', 'created_at'], name='clients_dat_user_id_b089d6_idx'),
        ),
        migrations.AddIndex(
            model_name='dataaccesslog',
            index=models.Index(fields=['resource_type', 'resource_id'], name='clients_dat_resourc_33d55f_idx'),
        ),
        migrations.AddIndex(
            model_name='clientpermission',
            index=models.Index(fields=['client', 'state'], name='clients_cli_client__6abd27_idx'),
        ),
        migrations.AddIndex(
            model_name='clientpermission',
            index=models.Index(fields=['permission', 'state'], name='clients_cli_permiss_c20609_idx'),
        ),
        migrations.AddIndex(
            model_name='clientpermission',
            index=models.Index(fields=['starts_at', 'expires_at'], name='clients_cli_starts__0417bd_idx'),
        ),
        migrations.AddIndex(
            model_name='clientpermission',
            index=models.Index(fields=['client', 'state', 'starts_at', 'expires_at'], name='clients_cli_client__cb08c5_idx'),
        ),
        migrations.AddIndex(
            model_name='supportticket',
            index=models.Index(fields=['status', 'priority'], name='clients_sup_status_4acb73_idx'),
        ),
        migrations.AddIndex(
            model_name='supportticket',
            index=models.Index(fields=['ticket_number'], name='clients_sup_ticket__65b8cb_idx'),
        ),
        migrations.AddIndex(
            model_name='useractivity',
            index=models.Index(fields=['user', 'activity_type', 'created_at'], name='clients_use_user_id_02802e_idx'),
        ),
        migrations.AddIndex(
            model_name='useractivity',
            index=models.Index(fields=['session_id'], name='clients_use_session_b98269_idx'),
        ),
    ]
