# Generated by Django 5.2.8 on 2026-01-16 06:59

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Module',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.CharField(db_index=True, help_text="Module key (e.g., 'users', 'breakdown.visit')", max_length=255, unique=True)),
                ('label', models.CharField(help_text='Human-readable module name', max_length=255)),
                ('description', models.TextField(blank=True, help_text='Module description')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('parent', models.ForeignKey(blank=True, help_text='Parent module for hierarchical structure', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='submodules', to='django_permission_engine.module')),
            ],
            options={
                'verbose_name': 'Module',
                'verbose_name_plural': 'Modules',
                'db_table': 'upr_modules',
                'ordering': ['key'],
            },
        ),
        migrations.CreateModel(
            name='Permission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.CharField(db_index=True, help_text='Permission key in format: module.capability', max_length=255, unique=True)),
                ('module', models.CharField(db_index=True, help_text='Module name this permission belongs to', max_length=100)),
                ('capability', models.CharField(help_text='Capability/action name', max_length=100)),
                ('label', models.CharField(help_text='Human-readable permission name', max_length=255)),
                ('description', models.TextField(blank=True, help_text='Detailed permission description')),
                ('is_active', models.BooleanField(default=True, help_text='Whether this permission is active')),
                ('is_deprecated', models.BooleanField(default=False, help_text='Whether this permission is deprecated')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='When this permission was created')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='When this permission was last updated')),
            ],
            options={
                'verbose_name': 'Permission',
                'verbose_name_plural': 'Permissions',
                'db_table': 'upr_permissions',
                'ordering': ['module', 'capability'],
                'indexes': [models.Index(fields=['module'], name='upr_permiss_module_72c6c0_idx'), models.Index(fields=['key'], name='upr_permiss_key_3f3d33_idx'), models.Index(fields=['module', 'capability'], name='upr_permiss_module_cd6865_idx')],
            },
        ),
        migrations.CreateModel(
            name='UserPermission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('granted_at', models.DateTimeField(auto_now_add=True)),
                ('granted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='upr_granted_permissions', to=settings.AUTH_USER_MODEL)),
                ('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_assignments', to='django_permission_engine.permission')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='upr_permissions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Permission',
                'verbose_name_plural': 'User Permissions',
                'db_table': 'upr_user_permissions',
                'unique_together': {('user', 'permission')},
            },
        ),
    ]
