# Generated by Django 5.2.8 on 2025-11-27 02:25

import django.db.models.deletion
import django_tenants.postgresql_backend.base
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='Tenant',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('schema_name', models.CharField(db_index=True, max_length=63, unique=True, validators=[django_tenants.postgresql_backend.base._check_schema_name])),
                ('name', models.CharField(max_length=100)),
                ('created_on', models.DateField(auto_now_add=True)),
                ('is_active', models.BooleanField(default=True)),
                ('subscription_tier', models.CharField(choices=[('FREE', 'Free Trial'), ('STARTER', 'Starter'), ('PROFESSIONAL', 'Professional'), ('ENTERPRISE', 'Enterprise')], default='FREE', max_length=50)),
                ('max_users', models.IntegerField(default=5)),
                ('max_resources', models.IntegerField(default=10)),
                ('contact_email', models.EmailField(blank=True, max_length=254)),
                ('phone', models.CharField(blank=True, max_length=20)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Domain',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('domain', models.CharField(db_index=True, max_length=253, unique=True)),
                ('is_primary', models.BooleanField(db_index=True, default=True)),
                ('is_custom_domain', models.BooleanField(default=False, help_text='True if this is a custom domain (not a subdomain of smoothschedule.com)')),
                ('route53_zone_id', models.CharField(blank=True, help_text='AWS Route53 Hosted Zone ID for this custom domain', max_length=100, null=True)),
                ('route53_record_set_id', models.CharField(blank=True, help_text='Route53 Record Set ID for DNS verification', max_length=100, null=True)),
                ('ssl_certificate_arn', models.CharField(blank=True, help_text='AWS ACM Certificate ARN for HTTPS', max_length=200, null=True)),
                ('verified_at', models.DateTimeField(blank=True, help_text='When the custom domain was verified via DNS', null=True)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='domains', to='core.tenant')),
            ],
            options={
                'ordering': ['domain'],
            },
        ),
        migrations.CreateModel(
            name='PermissionGrant',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(help_text="Specific action or permission being granted (e.g., 'view_billing', 'edit_settings')", max_length=100)),
                ('reason', models.TextField(blank=True, help_text='Justification for granting this permission (audit trail)')),
                ('granted_at', models.DateTimeField(auto_now_add=True)),
                ('expires_at', models.DateTimeField(help_text='When this permission grant expires')),
                ('revoked_at', models.DateTimeField(blank=True, help_text='If manually revoked before expiration', null=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address where grant was created', null=True)),
                ('user_agent', models.TextField(blank=True, help_text='Browser/client user agent')),
                ('grantee', models.ForeignKey(help_text='User who received the permission', on_delete=django.db.models.deletion.CASCADE, related_name='received_permissions', to=settings.AUTH_USER_MODEL)),
                ('grantor', models.ForeignKey(help_text='User who granted the permission', on_delete=django.db.models.deletion.CASCADE, related_name='granted_permissions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-granted_at'],
                'indexes': [models.Index(fields=['grantee', 'expires_at'], name='core_permis_grantee_560815_idx'), models.Index(fields=['grantor', 'granted_at'], name='core_permis_grantor_90dfdf_idx')],
            },
        ),
    ]
