# Generated by Django 6.0 on 2026-04-13 20:00

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0349_add_cta_signup_first_flag'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='SystemSkillProfile',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('skill_key', models.CharField(max_length=128)),
                ('profile_key', models.CharField(max_length=128)),
                ('label', models.CharField(max_length=128)),
                ('is_default', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='system_skill_profiles', to='api.organization')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='system_skill_profiles', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['skill_key', 'label', 'profile_key'],
            },
        ),
        migrations.CreateModel(
            name='SystemSkillProfileSecret',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('key', models.CharField(max_length=64)),
                ('encrypted_value', models.BinaryField()),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='secrets', to='api.systemskillprofile')),
            ],
            options={
                'ordering': ['key'],
            },
        ),
        migrations.AddIndex(
            model_name='systemskillprofile',
            index=models.Index(fields=['user', 'skill_key'], name='ssp_user_skill_idx'),
        ),
        migrations.AddIndex(
            model_name='systemskillprofile',
            index=models.Index(fields=['organization', 'skill_key'], name='ssp_org_skill_idx'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofile',
            constraint=models.CheckConstraint(condition=models.Q(models.Q(('organization__isnull', True), ('user__isnull', False)), models.Q(('organization__isnull', False), ('user__isnull', True)), _connector='OR'), name='system_skill_profile_exactly_one_owner'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofile',
            constraint=models.UniqueConstraint(condition=models.Q(('user__isnull', False)), fields=('user', 'skill_key', 'profile_key'), name='unique_system_skill_profile_user_key'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofile',
            constraint=models.UniqueConstraint(condition=models.Q(('organization__isnull', False)), fields=('organization', 'skill_key', 'profile_key'), name='unique_system_skill_profile_org_key'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofile',
            constraint=models.UniqueConstraint(condition=models.Q(('is_default', True), ('user__isnull', False)), fields=('user', 'skill_key'), name='unique_system_skill_profile_default_user'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofile',
            constraint=models.UniqueConstraint(condition=models.Q(('is_default', True), ('organization__isnull', False)), fields=('organization', 'skill_key'), name='unique_system_skill_profile_default_org'),
        ),
        migrations.AddIndex(
            model_name='systemskillprofilesecret',
            index=models.Index(fields=['profile', 'key'], name='ssp_secret_profile_key_idx'),
        ),
        migrations.AddConstraint(
            model_name='systemskillprofilesecret',
            constraint=models.UniqueConstraint(fields=('profile', 'key'), name='unique_system_skill_profile_secret_key'),
        ),
    ]
