# Generated by Django 6.0.1 on 2026-01-13 06:48

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):
    dependencies = [
        ('saas_base', '0005_userprofile_alter_useremail_table'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.RemoveField(
            model_name='member',
            name='permissions',
        ),
        migrations.RemoveField(
            model_name='group',
            name='permissions',
        ),
        migrations.RemoveField(
            model_name='role',
            name='permissions',
        ),
        migrations.AlterField(
            model_name='member',
            name='role',
            field=models.CharField(blank=True, max_length=50, null=True),
        ),
        migrations.RemoveField(
            model_name='member',
            name='email',
        ),
        migrations.RemoveField(
            model_name='member',
            name='inviter',
        ),
        migrations.RemoveField(
            model_name='member',
            name='name',
        ),
        migrations.RemoveField(
            model_name='member',
            name='status',
        ),
        migrations.AlterField(
            model_name='member',
            name='groups',
            field=models.ManyToManyField(blank=True, to='saas_base.group'),
        ),
        migrations.AlterField(
            model_name='member',
            name='user',
            field=models.ForeignKey(
                null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AlterField(
            model_name='tenant',
            name='owner',
            field=models.ForeignKey(
                null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.CreateModel(
            name='Invitation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('email', models.EmailField(max_length=254)),
                ('role', models.CharField(blank=True, max_length=50, null=True)),
                (
                    'status',
                    models.IntegerField(
                        choices=[(1, 'pending'), (2, 'sent'), (3, 'accepted'), (4, 'expired')], default=1
                    ),
                ),
                ('accepted_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ('groups', models.ManyToManyField(blank=True, to='saas_base.group')),
                (
                    'inviter',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name='sent_invitations',
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    'tenant',
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.SAAS_TENANT_MODEL),
                ),
            ],
            options={
                'verbose_name': 'invitation',
                'verbose_name_plural': 'invitations',
                'db_table': 'saas_member_invitation',
                'ordering': ['-created_at'],
                'unique_together': {('tenant', 'email')},
            },
        ),
        migrations.AddField(
            model_name='member',
            name='permissions',
            field=models.JSONField(default=list),
        ),
        migrations.AddField(
            model_name='group',
            name='permissions',
            field=models.JSONField(default=list),
        ),
        migrations.DeleteModel(
            name='Permission',
        ),
        migrations.DeleteModel(
            name='Role',
        ),
    ]
