# Generated by Django 5.2.8 on 2026-01-13 18:24

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):
    initial = True

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

    operations = [
        migrations.CreateModel(
            name="Organization",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "uid",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Public unique identifier for the organization.",
                    ),
                ),
                (
                    "clerk_id",
                    models.CharField(
                        db_index=True,
                        help_text="Unique identifier from Clerk.",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "name",
                    models.CharField(help_text="Organization name.", max_length=255),
                ),
                (
                    "slug",
                    models.SlugField(
                        help_text="URL-friendly organization identifier.",
                        max_length=255,
                    ),
                ),
                (
                    "image_url",
                    models.URLField(
                        blank=True,
                        default="",
                        help_text="URL to organization logo from Clerk.",
                        max_length=500,
                    ),
                ),
                (
                    "public_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Public metadata from Clerk.",
                    ),
                ),
                (
                    "private_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Private metadata from Clerk.",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether the organization is active.",
                    ),
                ),
                (
                    "members_count",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of members in the organization."
                    ),
                ),
                (
                    "pending_invitations_count",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of pending invitations."
                    ),
                ),
                (
                    "max_allowed_memberships",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Maximum allowed memberships (0 = unlimited).",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When the organization was created in Clerk.",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="When the organization was last updated.",
                    ),
                ),
            ],
            options={
                "verbose_name": "Organization",
                "verbose_name_plural": "Organizations",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["clerk_id"], name="clerk_organ_clerk_i_b2b811_idx"
                    ),
                    models.Index(fields=["slug"], name="clerk_organ_slug_6c2124_idx"),
                    models.Index(
                        fields=["is_active"], name="clerk_organ_is_acti_67b48f_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="OrganizationInvitation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "clerk_invitation_id",
                    models.CharField(
                        db_index=True,
                        help_text="Unique invitation identifier from Clerk.",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "email_address",
                    models.EmailField(
                        help_text="Email address of the invitee.", max_length=254
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        default="member",
                        help_text="Role the user will have upon accepting.",
                        max_length=100,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("accepted", "Accepted"),
                            ("revoked", "Revoked"),
                        ],
                        db_index=True,
                        default="pending",
                        help_text="Invitation status.",
                        max_length=20,
                    ),
                ),
                (
                    "public_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Public metadata from Clerk.",
                    ),
                ),
                (
                    "private_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Private metadata from Clerk.",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When the invitation was created.",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True, help_text="When the invitation was last updated."
                    ),
                ),
                (
                    "inviter",
                    models.ForeignKey(
                        blank=True,
                        help_text="The user who sent the invitation.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="sent_invitations",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        help_text="The organization.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="invitations",
                        to="clerk_organizations.organization",
                    ),
                ),
            ],
            options={
                "verbose_name": "Organization Invitation",
                "verbose_name_plural": "Organization Invitations",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["clerk_invitation_id"],
                        name="clerk_organ_clerk_i_53d078_idx",
                    ),
                    models.Index(
                        fields=["status"], name="clerk_organ_status_bef241_idx"
                    ),
                    models.Index(
                        fields=["email_address"], name="clerk_organ_email_a_b3359c_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="OrganizationMember",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "clerk_membership_id",
                    models.CharField(
                        db_index=True,
                        help_text="Unique membership identifier from Clerk.",
                        max_length=255,
                        unique=True,
                    ),
                ),
                (
                    "role",
                    models.CharField(
                        default="member",
                        help_text="User's role in the organization (e.g., 'admin', 'member').",
                        max_length=100,
                    ),
                ),
                (
                    "public_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Public metadata from Clerk.",
                    ),
                ),
                (
                    "private_metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Private metadata from Clerk.",
                    ),
                ),
                (
                    "joined_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When the user joined the organization.",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True, help_text="When the membership was last updated."
                    ),
                ),
                (
                    "organization",
                    models.ForeignKey(
                        help_text="The organization.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="cached_members",
                        to="clerk_organizations.organization",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="The user.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="organization_memberships",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Organization Member",
                "verbose_name_plural": "Organization Members",
                "ordering": ["-joined_at"],
                "indexes": [
                    models.Index(
                        fields=["clerk_membership_id"],
                        name="clerk_organ_clerk_m_10f2c5_idx",
                    ),
                    models.Index(fields=["role"], name="clerk_organ_role_645ce1_idx"),
                ],
                "unique_together": {("organization", "user")},
            },
        ),
    ]
