# Generated by Django 5.2.4 on 2025-08-03 01:56

import django.contrib.auth.models
import django.contrib.auth.validators
import django.core.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='CustomUser',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True)),
                ('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')),
                ('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')),
                ('email', models.EmailField(blank=True, max_length=254, null=True, unique=True)),
                ('role', models.CharField(choices=[('admin', 'Admin'), ('staff', 'Staff'), ('borrower', 'Borrower')], default='borrower', max_length=20)),
                ('phone_number', models.CharField(max_length=17, unique=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+254XXXXXXXXX'", regex='^\\+?254?\\d{9,15}$')])),
                ('id_number', models.CharField(blank=True, max_length=20, null=True, unique=True)),
                ('date_of_birth', models.DateField(blank=True, null=True)),
                ('gender', models.CharField(blank=True, choices=[('male', 'Male'), ('female', 'Female')], max_length=10, null=True)),
                ('marital_status', models.CharField(blank=True, choices=[('single', 'Single'), ('married', 'Married'), ('divorced', 'Divorced'), ('widowed', 'Widowed')], max_length=20, null=True)),
                ('nationality', models.CharField(blank=True, max_length=50, null=True)),
                ('physical_address', models.TextField(blank=True, null=True)),
                ('postal_address', models.CharField(blank=True, max_length=100, null=True)),
                ('postal_code', models.CharField(blank=True, max_length=20, null=True)),
                ('city', models.CharField(blank=True, max_length=100, null=True)),
                ('country', models.CharField(default='Kenya', max_length=100)),
                ('business_name', models.CharField(blank=True, max_length=200, null=True)),
                ('business_type', models.CharField(blank=True, max_length=100, null=True)),
                ('business_address', models.TextField(blank=True, null=True)),
                ('business_registration_number', models.CharField(blank=True, max_length=50, null=True)),
                ('id_document', models.FileField(blank=True, null=True, upload_to='kyc/id_documents/')),
                ('selfie', models.FileField(blank=True, null=True, upload_to='kyc/selfies/')),
                ('utility_bill', models.FileField(blank=True, null=True, upload_to='kyc/utility_bills/')),
                ('bank_statement', models.FileField(blank=True, null=True, upload_to='kyc/bank_statements/')),
                ('business_license', models.FileField(blank=True, null=True, upload_to='kyc/business_licenses/')),
                ('tax_certificate', models.FileField(blank=True, null=True, upload_to='kyc/tax_certificates/')),
                ('other_documents', models.JSONField(blank=True, default=list, help_text='List of additional document URLs and descriptions')),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('suspended', 'Suspended'), ('blacklisted', 'Blacklisted')], default='active', max_length=20)),
                ('is_verified', models.BooleanField(default=False)),
                ('verification_date', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('employer', models.CharField(blank=True, max_length=200, null=True)),
                ('monthly_income', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=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')),
                ('verified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='verified_users', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'users',
                'ordering': ['-date_joined'],
            },
            managers=[
                ('objects', django.contrib.auth.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='OTPVerification',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('otp_code', models.CharField(max_length=6)),
                ('is_used', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('expires_at', models.DateTimeField()),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'otp_verifications',
            },
        ),
        migrations.CreateModel(
            name='RolePermission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('admin', 'Admin'), ('team_leader', 'Team Leader'), ('loan_officer', 'Loan Officer'), ('secretary', 'Secretary'), ('auditor', 'Auditor'), ('borrower', 'Borrower')], max_length=20)),
                ('module', models.CharField(choices=[('users', 'User Management'), ('loans', 'Loan Management'), ('reports', 'Reports & Analytics'), ('documents', 'Document Management'), ('settings', 'System Settings'), ('notifications', 'Notifications'), ('audit', 'Audit Logs'), ('kyc', 'KYC Management'), ('payments', 'Payment Management'), ('communications', 'Communications')], max_length=20)),
                ('action', models.CharField(choices=[('view', 'View'), ('create', 'Create'), ('edit', 'Edit'), ('delete', 'Delete'), ('approve', 'Approve'), ('reject', 'Reject'), ('export', 'Export'), ('import', 'Import'), ('manage', 'Manage')], max_length=20)),
                ('is_allowed', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'role_permissions',
                'ordering': ['role', 'module', 'action'],
                'unique_together': {('role', 'module', 'action')},
            },
        ),
        migrations.CreateModel(
            name='UserAccessLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(max_length=50)),
                ('module', models.CharField(max_length=50)),
                ('object_type', models.CharField(blank=True, max_length=50, null=True)),
                ('object_id', models.CharField(blank=True, max_length=50, null=True)),
                ('description', models.TextField()),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.CharField(blank=True, max_length=500, null=True)),
                ('session_id', models.CharField(blank=True, max_length=100, null=True)),
                ('accessed_at', models.DateTimeField(auto_now_add=True)),
                ('response_time', models.FloatField(blank=True, null=True)),
                ('status_code', models.IntegerField(blank=True, null=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='access_logs', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'user_access_logs',
                'ordering': ['-accessed_at'],
                'indexes': [models.Index(fields=['user', 'accessed_at'], name='user_access_user_id_416563_idx'), models.Index(fields=['action', 'accessed_at'], name='user_access_action_a90b01_idx'), models.Index(fields=['module', 'accessed_at'], name='user_access_module_47fa23_idx')],
            },
        ),
    ]
