# Generated by Django 5.2.4 on 2025-09-01 05:26

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


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0009_customuser_registration_fee_amount_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='DefaultRolePermission',
            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'), ('borrower', 'Borrower')], max_length=20)),
                ('module', models.CharField(choices=[('dashboard', 'Dashboard'), ('users', 'User Management'), ('clients', 'Client Management'), ('loans', 'Loan Management'), ('applications', 'Loan Applications'), ('repayments', 'Repayments'), ('reports', 'Reports & Analytics'), ('documents', 'Document Management'), ('settings', 'System Settings'), ('notifications', 'Notifications'), ('audit', 'Audit Logs'), ('kyc', 'KYC Management'), ('payments', 'Payment Management'), ('communications', 'Communications'), ('portfolio', 'Portfolio Management'), ('receipts', 'Receipt Management'), ('statements', 'Statement Generation'), ('media', 'Media Management'), ('backup', 'Backup & Restore'), ('system', 'System Administration')], 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'), ('assign', 'Assign'), ('reassign', 'Reassign'), ('suspend', 'Suspend'), ('activate', 'Activate'), ('verify', 'Verify'), ('generate', 'Generate'), ('download', 'Download'), ('upload', 'Upload'), ('share', 'Share'), ('print', 'Print')], max_length=20)),
                ('is_allowed', models.BooleanField(default=False)),
                ('description', models.TextField(blank=True, help_text='Description of what this permission allows', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'default_role_permissions',
                'ordering': ['role', 'module', 'action'],
            },
        ),
        migrations.CreateModel(
            name='UserPermission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('module', models.CharField(choices=[('dashboard', 'Dashboard'), ('users', 'User Management'), ('clients', 'Client Management'), ('loans', 'Loan Management'), ('applications', 'Loan Applications'), ('repayments', 'Repayments'), ('reports', 'Reports & Analytics'), ('documents', 'Document Management'), ('settings', 'System Settings'), ('notifications', 'Notifications'), ('audit', 'Audit Logs'), ('kyc', 'KYC Management'), ('payments', 'Payment Management'), ('communications', 'Communications'), ('portfolio', 'Portfolio Management'), ('receipts', 'Receipt Management'), ('statements', 'Statement Generation'), ('media', 'Media Management'), ('backup', 'Backup & Restore'), ('system', 'System Administration')], 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'), ('assign', 'Assign'), ('reassign', 'Reassign'), ('suspend', 'Suspend'), ('activate', 'Activate'), ('verify', 'Verify'), ('generate', 'Generate'), ('download', 'Download'), ('upload', 'Upload'), ('share', 'Share'), ('print', 'Print')], max_length=20)),
                ('is_allowed', models.BooleanField(default=False)),
                ('reason', models.TextField(blank=True, help_text='Reason for custom permission', null=True)),
                ('expires_at', models.DateTimeField(blank=True, help_text='When this permission expires', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'db_table': 'user_permissions',
                'ordering': ['user', 'module', 'action'],
            },
        ),
        migrations.AddField(
            model_name='rolepermission',
            name='is_default',
            field=models.BooleanField(default=True, help_text='Whether this is a default permission for the role'),
        ),
        migrations.AlterField(
            model_name='rolepermission',
            name='action',
            field=models.CharField(choices=[('view', 'View'), ('create', 'Create'), ('edit', 'Edit'), ('delete', 'Delete'), ('approve', 'Approve'), ('reject', 'Reject'), ('export', 'Export'), ('import', 'Import'), ('manage', 'Manage'), ('assign', 'Assign'), ('reassign', 'Reassign'), ('suspend', 'Suspend'), ('activate', 'Activate'), ('verify', 'Verify'), ('generate', 'Generate'), ('download', 'Download'), ('upload', 'Upload'), ('share', 'Share'), ('print', 'Print')], max_length=20),
        ),
        migrations.AlterField(
            model_name='rolepermission',
            name='module',
            field=models.CharField(choices=[('dashboard', 'Dashboard'), ('users', 'User Management'), ('clients', 'Client Management'), ('loans', 'Loan Management'), ('applications', 'Loan Applications'), ('repayments', 'Repayments'), ('reports', 'Reports & Analytics'), ('documents', 'Document Management'), ('settings', 'System Settings'), ('notifications', 'Notifications'), ('audit', 'Audit Logs'), ('kyc', 'KYC Management'), ('payments', 'Payment Management'), ('communications', 'Communications'), ('portfolio', 'Portfolio Management'), ('receipts', 'Receipt Management'), ('statements', 'Statement Generation'), ('media', 'Media Management'), ('backup', 'Backup & Restore'), ('system', 'System Administration')], max_length=20),
        ),
        migrations.AddIndex(
            model_name='rolepermission',
            index=models.Index(fields=['role', 'is_default'], name='role_permis_role_056d99_idx'),
        ),
        migrations.AddIndex(
            model_name='rolepermission',
            index=models.Index(fields=['module', 'action'], name='role_permis_module_98f632_idx'),
        ),
        migrations.AddIndex(
            model_name='defaultrolepermission',
            index=models.Index(fields=['role'], name='default_rol_role_2fe672_idx'),
        ),
        migrations.AddIndex(
            model_name='defaultrolepermission',
            index=models.Index(fields=['module', 'action'], name='default_rol_module_eae3e9_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='defaultrolepermission',
            unique_together={('role', 'module', 'action')},
        ),
        migrations.AddField(
            model_name='userpermission',
            name='granted_by',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='permissions_granted', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='userpermission',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_permissions', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddIndex(
            model_name='userpermission',
            index=models.Index(fields=['user', 'expires_at'], name='user_permis_user_id_718a3c_idx'),
        ),
        migrations.AddIndex(
            model_name='userpermission',
            index=models.Index(fields=['module', 'action'], name='user_permis_module_f508fb_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='userpermission',
            unique_together={('user', 'module', 'action')},
        ),
    ]
