# Generated by Django 6.0.1 on 2026-01-22 03:34

import uuid

from django.conf import settings
from django.db import migrations, models
from django.utils import timezone

from saas.db.defaults import set_invitation_expires_at


class Migration(migrations.Migration):
    initial = True

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

    operations = [
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                (
                    'user',
                    models.OneToOneField(
                        on_delete=models.CASCADE,
                        primary_key=True,
                        related_name='profile',
                        serialize=False,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                ('bio', models.TextField(blank=True, max_length=500)),
                ('birth_date', models.DateField(blank=True, null=True)),
                ('website', models.URLField(blank=True, null=True)),
                ('avatar_url', models.URLField(blank=True, null=True)),
                ('region', models.CharField(blank=True, max_length=4, null=True)),
                ('locale', models.CharField(blank=True, max_length=10, null=True)),
                ('timezone', models.CharField(default='UTC', help_text="e.g., 'America/New_York'", max_length=50)),
            ],
            options={
                'db_table': 'saas_user_profile',
            },
        ),
        migrations.CreateModel(
            name='UserEmail',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('email', models.EmailField(max_length=254, unique=True)),
                ('verified', models.BooleanField(default=False)),
                ('primary', models.BooleanField(db_index=True, default=False)),
                ('created_at', models.DateTimeField(db_index=True, default=timezone.now)),
                (
                    'user',
                    models.ForeignKey(on_delete=models.CASCADE, related_name='emails', to=settings.AUTH_USER_MODEL),
                ),
            ],
            options={
                'verbose_name': 'email',
                'verbose_name_plural': 'emails',
                'db_table': 'saas_user_email',
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='Invitation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('token', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('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'), (5, 'declined')],
                        default=1,
                    ),
                ),
                ('expires_at', models.DateTimeField(default=set_invitation_expires_at)),
                ('accepted_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(db_index=True, default=timezone.now)),
                ('inviter', models.ForeignKey(null=True, on_delete=models.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(on_delete=models.CASCADE, to=settings.SAAS_TENANT_MODEL)),
            ],
            options={
                'verbose_name': 'invitation',
                'verbose_name_plural': 'invitations',
                'db_table': 'saas_identity_invitation',
                'ordering': ['-created_at'],
                'unique_together': {('tenant', 'email')},
            },
        ),
        migrations.CreateModel(
            name='Membership',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(db_index=True, default=timezone.now)),
                ('role', models.CharField(blank=True, max_length=50, null=True)),
                ('tenant', models.ForeignKey(on_delete=models.CASCADE, to=settings.SAAS_TENANT_MODEL)),
                ('user', models.ForeignKey(null=True, on_delete=models.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'membership',
                'verbose_name_plural': 'memberships',
                'db_table': 'saas_identity_membership',
                'ordering': ['-created_at'],
                'unique_together': {('tenant', 'user')},
            },
        ),
    ]
