# Generated by Django 5.2.11 on 2026-02-11 17:02

import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('tenant', '0001_initial'),
        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')),
                ('name', models.CharField(help_text="Unique module identifier (e.g., 'accounting', 'hrm')", max_length=100, unique=True, validators=[django.core.validators.RegexValidator(message='Module name must be lowercase alphanumeric with underscores', regex='^[a-z][a-z0-9_]*$')])),
                ('display_name', models.CharField(help_text='Human-readable name', max_length=255)),
                ('description', models.TextField(blank=True, help_text='Module description')),
                ('version', models.CharField(default='1.0.0', help_text='Current module version (semver)', max_length=50)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('deprecated', 'Deprecated'), ('beta', 'Beta'), ('coming_soon', 'Coming Soon')], default='active', max_length=20)),
                ('category', models.CharField(blank=True, help_text="Module category (e.g., 'Finance', 'HR', 'Operations')", max_length=100)),
                ('tags', models.JSONField(blank=True, default=list, help_text='Tags for filtering and searching')),
                ('icon', models.CharField(blank=True, help_text='Icon name or path', max_length=100)),
                ('color', models.CharField(blank=True, help_text='Primary color for the module', max_length=20)),
                ('default_settings', models.JSONField(blank=True, default=dict, help_text='Default settings for this module')),
                ('api_prefix', models.CharField(blank=True, help_text="API URL prefix (e.g., '/api/v1/accounting')", max_length=100)),
                ('supported_api_versions', models.JSONField(blank=True, default=list, help_text='List of supported API versions')),
                ('provided_permissions', models.JSONField(blank=True, default=list, help_text='List of permission codenames this module provides')),
                ('published_events', models.JSONField(blank=True, default=list, help_text='Events this module publishes')),
                ('consumed_events', models.JSONField(blank=True, default=list, help_text='Events this module consumes')),
                ('manifest', models.JSONField(blank=True, default=dict, help_text='Full manifest.json content')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('dependencies', models.ManyToManyField(blank=True, help_text='Other modules this module depends on', related_name='dependents', to='core_module_registry.module')),
            ],
            options={
                'verbose_name': 'Module',
                'verbose_name_plural': 'Modules',
                'db_table': 'modules',
                'ordering': ['category', 'display_name'],
            },
        ),
        migrations.CreateModel(
            name='Feature',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text='Feature identifier', max_length=100)),
                ('display_name', models.CharField(help_text='Human-readable name', max_length=255)),
                ('description', models.TextField(blank=True)),
                ('is_enabled', models.BooleanField(default=True, help_text='Global feature toggle')),
                ('is_beta', models.BooleanField(default=False, help_text='Is this a beta feature?')),
                ('minimum_license', models.CharField(choices=[('free', 'Free'), ('trial', 'Trial'), ('basic', 'Basic'), ('professional', 'Professional'), ('enterprise', 'Enterprise'), ('custom', 'Custom')], default='free', help_text='Minimum license type required for this feature', max_length=20)),
                ('rollout_percentage', models.PositiveIntegerField(default=100, help_text='Percentage of tenants to enable this for (0-100)')),
                ('config_schema', models.JSONField(blank=True, default=dict, help_text='JSON Schema for feature configuration')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('depends_on', models.ManyToManyField(blank=True, related_name='required_by', to='core_module_registry.feature')),
                ('module', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='features', to='core_module_registry.module')),
            ],
            options={
                'verbose_name': 'Feature',
                'verbose_name_plural': 'Features',
                'db_table': 'features',
                'unique_together': {('module', 'name')},
            },
        ),
        migrations.CreateModel(
            name='TenantFeatureOverride',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('is_enabled', models.BooleanField(help_text='Override: is this feature enabled for this tenant?')),
                ('reason', models.TextField(blank=True, help_text='Reason for this override')),
                ('expires_at', models.DateTimeField(blank=True, help_text='When this override expires', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('feature', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tenant_overrides', to='core_module_registry.feature')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='tenant.tenant')),
            ],
            options={
                'verbose_name': 'Tenant Feature Override',
                'verbose_name_plural': 'Tenant Feature Overrides',
                'db_table': 'tenant_feature_overrides',
                'unique_together': {('tenant', 'feature')},
            },
        ),
        migrations.CreateModel(
            name='TenantModule',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('is_enabled', models.BooleanField(default=True, help_text='Is this module enabled for the tenant?')),
                ('license_type', models.CharField(choices=[('free', 'Free'), ('trial', 'Trial'), ('basic', 'Basic'), ('professional', 'Professional'), ('enterprise', 'Enterprise'), ('custom', 'Custom')], default='trial', max_length=20)),
                ('licensed_at', models.DateTimeField(auto_now_add=True, help_text='When the license was granted')),
                ('expires_at', models.DateTimeField(blank=True, help_text='When the license expires (null = never)', null=True)),
                ('max_users', models.PositiveIntegerField(blank=True, help_text='Maximum users for this module (null = unlimited)', null=True)),
                ('max_records', models.PositiveIntegerField(blank=True, help_text='Maximum records (null = unlimited)', null=True)),
                ('settings', models.JSONField(blank=True, default=dict, help_text='Tenant-specific module settings')),
                ('enabled_features', models.JSONField(blank=True, default=list, help_text='List of enabled feature flags')),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('module', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tenant_licenses', to='core_module_registry.module')),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='licensed_modules', to='tenant.tenant')),
            ],
            options={
                'verbose_name': 'Tenant Module License',
                'verbose_name_plural': 'Tenant Module Licenses',
                'db_table': 'tenant_modules',
                'unique_together': {('tenant', 'module')},
            },
        ),
    ]
