# Generated by Django 4.2.7 on 2025-07-08 12:25

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for the user', primary_key=True, serialize=False)),
                ('email', models.EmailField(help_text="User's email address (used for login)", max_length=254, unique=True)),
                ('username', models.CharField(blank=True, help_text='Optional username for display purposes', max_length=150, null=True, unique=True)),
                ('first_name', models.CharField(blank=True, help_text="User's first name", max_length=150)),
                ('last_name', models.CharField(blank=True, help_text="User's last name", max_length=150)),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into the admin site')),
                ('is_verified', models.BooleanField(default=False, help_text="Designates whether the user's email has been verified")),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, help_text='Date when the user account was created')),
                ('last_login', models.DateTimeField(blank=True, help_text='Last time the user logged in', null=True)),
                ('last_activity', models.DateTimeField(blank=True, help_text='Last time the user was active in the system', null=True)),
                ('failed_login_attempts', models.PositiveIntegerField(default=0, help_text='Number of consecutive failed login attempts')),
                ('account_locked_until', models.DateTimeField(blank=True, help_text='Account lockout expiration time', null=True)),
                ('password_changed_at', models.DateTimeField(default=django.utils.timezone.now, help_text='When the password was last changed')),
                ('mfa_enabled', models.BooleanField(default=False, help_text='Whether multi-factor authentication is enabled')),
                ('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={
                'verbose_name': 'User',
                'verbose_name_plural': 'Users',
                'db_table': 'accounts_users',
                'ordering': ['-date_joined'],
            },
        ),
        migrations.CreateModel(
            name='Department',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(help_text="Department name (e.g., 'Marketing', 'Sales', 'IT')", max_length=100, unique=True)),
                ('code', models.CharField(help_text="Department code (e.g., 'MKT', 'SALES', 'IT')", max_length=20, unique=True, validators=[django.core.validators.RegexValidator('^[A-Z]{2,20}$', 'Code must be uppercase letters only')])),
                ('description', models.TextField(blank=True, help_text="Detailed description of the department's responsibilities")),
                ('is_active', models.BooleanField(default=True, help_text='Whether this department is currently active')),
                ('head', models.ForeignKey(blank=True, help_text='Department head/manager', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='headed_departments', to=settings.AUTH_USER_MODEL)),
                ('parent', models.ForeignKey(blank=True, help_text='Parent department for hierarchical structure', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='accounts.department')),
            ],
            options={
                'verbose_name': 'Department',
                'verbose_name_plural': 'Departments',
                'db_table': 'accounts_departments',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Role',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(help_text="Role name (e.g., 'Campaign Manager', 'Analytics Viewer')", max_length=100, unique=True)),
                ('code', models.CharField(help_text="Role code for programmatic access (e.g., 'campaign_manager')", max_length=50, unique=True, validators=[django.core.validators.RegexValidator('^[a-z_]+$', 'Code must be lowercase with underscores only')])),
                ('description', models.TextField(blank=True, help_text="Detailed description of the role's responsibilities and permissions")),
                ('role_type', models.CharField(choices=[('system', 'System Role'), ('custom', 'Custom Role'), ('department', 'Department Role'), ('project', 'Project Role')], default='custom', help_text='Type of role for categorization', max_length=20)),
                ('level', models.PositiveIntegerField(default=1, help_text='Role hierarchy level (1=highest, 5=lowest)')),
                ('is_active', models.BooleanField(default=True, help_text='Whether this role is currently active')),
                ('is_default', models.BooleanField(default=False, help_text='Whether this is a default role for new users')),
                ('parent_role', models.ForeignKey(blank=True, help_text='Parent role for inheritance', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='child_roles', to='accounts.role')),
                ('permissions', models.ManyToManyField(blank=True, help_text='Specific permissions assigned to this role', to='auth.permission')),
            ],
            options={
                'verbose_name': 'Role',
                'verbose_name_plural': 'Roles',
                'db_table': 'accounts_roles',
                'ordering': ['level', 'name'],
            },
        ),
        migrations.CreateModel(
            name='UserSession',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('session_key', models.CharField(help_text='Django session key', max_length=40, unique=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address of the session', null=True)),
                ('user_agent', models.TextField(blank=True, help_text='Browser user agent string')),
                ('location', models.CharField(blank=True, help_text='Geographic location (if available)', max_length=200)),
                ('is_active', models.BooleanField(default=True, help_text='Whether the session is currently active')),
                ('last_activity', models.DateTimeField(default=django.utils.timezone.now, help_text='Last activity timestamp')),
                ('expires_at', models.DateTimeField(help_text='When the session expires')),
                ('user', models.ForeignKey(help_text='User associated with this session', on_delete=django.db.models.deletion.CASCADE, related_name='sessions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Session',
                'verbose_name_plural': 'User Sessions',
                'db_table': 'accounts_user_sessions',
                'ordering': ['-last_activity'],
            },
        ),
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('phone', models.CharField(blank=True, help_text="User's phone number", max_length=20, validators=[django.core.validators.RegexValidator('^\\+?[\\d\\s\\-\\(\\)]+$', 'Enter a valid phone number')])),
                ('avatar', models.ImageField(blank=True, help_text="User's profile picture", null=True, upload_to='avatars/%Y/%m/')),
                ('bio', models.TextField(blank=True, help_text='Brief biography or description', max_length=500)),
                ('date_of_birth', models.DateField(blank=True, help_text="User's date of birth", null=True)),
                ('job_title', models.CharField(blank=True, help_text="User's job title or position", max_length=100)),
                ('employee_id', models.CharField(blank=True, help_text='Employee ID or staff number', max_length=50, null=True, unique=True)),
                ('hire_date', models.DateField(blank=True, help_text='Date when the user was hired', null=True)),
                ('timezone', models.CharField(default='UTC', help_text="User's preferred timezone", max_length=50)),
                ('language', models.CharField(default='en', help_text="User's preferred language", max_length=10)),
                ('theme', models.CharField(choices=[('light', 'Light Theme'), ('dark', 'Dark Theme'), ('auto', 'Auto (System)')], default='light', help_text="User's preferred UI theme", max_length=20)),
                ('notifications_enabled', models.BooleanField(default=True, help_text='Whether to receive notifications')),
                ('email_notifications', models.BooleanField(default=True, help_text='Whether to receive email notifications')),
                ('address', models.TextField(blank=True, help_text="User's physical address")),
                ('emergency_contact_name', models.CharField(blank=True, help_text='Emergency contact person name', max_length=100)),
                ('emergency_contact_phone', models.CharField(blank=True, help_text='Emergency contact phone number', max_length=20)),
                ('department', models.ForeignKey(blank=True, help_text="User's department", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='users', to='accounts.department')),
                ('manager', models.ForeignKey(blank=True, help_text="User's direct manager", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='subordinates', to=settings.AUTH_USER_MODEL)),
                ('user', models.OneToOneField(help_text='Associated user account', on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Profile',
                'verbose_name_plural': 'User Profiles',
                'db_table': 'accounts_user_profiles',
            },
        ),
        migrations.CreateModel(
            name='PasswordResetToken',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('token', models.UUIDField(default=uuid.uuid4, help_text='Unique reset token', unique=True)),
                ('expires_at', models.DateTimeField(help_text='When the token expires')),
                ('is_used', models.BooleanField(default=False, help_text='Whether the token has been used')),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address from which reset was requested', null=True)),
                ('user', models.ForeignKey(help_text='User requesting password reset', on_delete=django.db.models.deletion.CASCADE, related_name='reset_tokens', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Password Reset Token',
                'verbose_name_plural': 'Password Reset Tokens',
                'db_table': 'accounts_password_reset_tokens',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserRole',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('assigned_at', models.DateTimeField(default=django.utils.timezone.now, help_text='When this role was assigned')),
                ('valid_from', models.DateTimeField(default=django.utils.timezone.now, help_text='When this role assignment becomes valid')),
                ('valid_until', models.DateTimeField(blank=True, help_text='When this role assignment expires', null=True)),
                ('is_active', models.BooleanField(default=True, help_text='Whether this role assignment is currently active')),
                ('notes', models.TextField(blank=True, help_text='Additional notes about this role assignment')),
                ('assigned_by', models.ForeignKey(blank=True, help_text='User who assigned this role', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_roles', to=settings.AUTH_USER_MODEL)),
                ('role', models.ForeignKey(help_text='Role assigned to the user', on_delete=django.db.models.deletion.CASCADE, to='accounts.role')),
                ('user', models.ForeignKey(help_text='User assigned to this role', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Role',
                'verbose_name_plural': 'User Roles',
                'db_table': 'accounts_user_roles',
                'ordering': ['-assigned_at'],
                'unique_together': {('user', 'role')},
            },
        ),
        migrations.CreateModel(
            name='UserActivity',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('action', models.CharField(choices=[('login', 'Login'), ('logout', 'Logout'), ('create', 'Create'), ('read', 'View'), ('update', 'Update'), ('delete', 'Delete'), ('export', 'Export'), ('import', 'Import'), ('admin', 'Admin Action')], help_text='Type of action performed', max_length=20)),
                ('object_type', models.CharField(blank=True, help_text='Type of object affected (model name)', max_length=50)),
                ('object_id', models.CharField(blank=True, help_text='ID of the affected object', max_length=50)),
                ('object_repr', models.CharField(blank=True, help_text='String representation of the affected object', max_length=200)),
                ('details', models.JSONField(blank=True, default=dict, help_text='Additional details about the action')),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address from which the action was performed', null=True)),
                ('user_agent', models.TextField(blank=True, help_text='Browser user agent string')),
                ('user', models.ForeignKey(help_text='User who performed the action', on_delete=django.db.models.deletion.CASCADE, related_name='activities', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Activity',
                'verbose_name_plural': 'User Activities',
                'db_table': 'accounts_user_activities',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['user', 'action'], name='accounts_us_user_id_8569cb_idx'), models.Index(fields=['created_at'], name='accounts_us_created_e9feea_idx'), models.Index(fields=['object_type', 'object_id'], name='accounts_us_object__bf82e8_idx')],
            },
        ),
    ]
