# Generated by Django 5.2.6 on 2025-09-19 08:03

import django.core.validators
import django.db.models.deletion
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='SettingCategory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.SlugField(max_length=64, unique=True)),
                ('title', models.CharField(max_length=128)),
            ],
        ),
        migrations.CreateModel(
            name='SettingDefinition',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.CharField(help_text='Ключ настройки. Используется для обращения к настройке в коде', max_length=120, unique=True, validators=[django.core.validators.RegexValidator(code='invalid_key', message='Ключ настройки может состоять из латинских букв, цифр и знака подчеркивания', regex='^[a-z0-9_\\.\\-]+$')], verbose_name='Ключ настройки')),
                ('type', models.CharField(choices=[('bool', 'Логический'), ('int', 'Целое'), ('float', 'Вещественное'), ('str', 'Строка'), ('json', 'JSON'), ('choice', 'Выбор'), ('datetime', 'Дата/время'), ('duration', 'Длительность (сек.)')], help_text='Тип настройки', max_length=15, verbose_name='Тип')),
                ('title', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True, help_text='Описание настройки', verbose_name='Описание')),
                ('default', models.JSONField(blank=True, null=True)),
                ('choices', models.JSONField(blank=True, null=True)),
                ('required', models.BooleanField(default=False)),
                ('enabled', models.BooleanField(default=True)),
                ('editable', models.BooleanField(default=True)),
                ('frontend', models.BooleanField(default=False)),
                ('category', models.ForeignKey(blank=True, help_text='Категория настройки', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='definitions', to='confetti.settingcategory', verbose_name='Категория')),
            ],
            options={
                'ordering': ['key'],
            },
        ),
        migrations.CreateModel(
            name='SettingValue',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('scope', models.CharField(choices=[('global', 'Глобальная'), ('user', 'Пользовательская')], help_text='scope настройки', max_length=15, verbose_name='scope')),
                ('value', models.JSONField(blank=True, null=True)),
                ('definition', models.ForeignKey(help_text='Настройка', on_delete=django.db.models.deletion.CASCADE, related_name='values', to='confetti.settingdefinition', verbose_name='Настройка')),
                ('user', models.ForeignKey(blank=True, help_text='Пользователь', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='settings', to=settings.AUTH_USER_MODEL, verbose_name='Пользователь')),
            ],
            options={
                'constraints': [models.UniqueConstraint(fields=('definition', 'scope', 'user'), name='unique_setting_value')],
            },
        ),
    ]
