# Generated by Django 5.1.3 on 2026-05-23 09:26

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("tenants", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="SettingValue",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, db_index=True, verbose_name="created at"
                    ),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="updated at")),
                (
                    "public_id",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="public id",
                    ),
                ),
                ("key", models.CharField(db_index=True, max_length=128, verbose_name="key")),
                (
                    "scope",
                    models.CharField(
                        choices=[
                            ("system", "System"),
                            ("tenant", "Tenant"),
                            ("org", "Organization Node"),
                            ("module", "Module"),
                            ("user", "User"),
                        ],
                        db_index=True,
                        max_length=16,
                        verbose_name="scope",
                    ),
                ),
                (
                    "scope_id",
                    models.CharField(
                        blank=True, db_index=True, max_length=128, verbose_name="scope id"
                    ),
                ),
                ("value", models.JSONField(verbose_name="value")),
                (
                    "tenant",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="tenants.tenant",
                    ),
                ),
                (
                    "updated_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "setting value",
                "verbose_name_plural": "setting values",
                "indexes": [
                    models.Index(
                        fields=["tenant", "scope", "key"], name="app_setting_tenant__90730d_idx"
                    )
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("key", "scope", "scope_id", "tenant"),
                        name="app_settings_value_unique",
                    )
                ],
            },
        ),
    ]
