# Generated by Django 5.2.4 on 2025-09-25 01:03

import django.core.validators
import django.db.models.deletion
import re
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0046_create_sys_sigil_root"),
    ]

    operations = [
        migrations.CreateModel(
            name="SocialProfile",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "network",
                    models.CharField(
                        choices=[("bluesky", "Bluesky")],
                        default="bluesky",
                        help_text="Select the social network you want to connect. Only Bluesky is supported at the moment.",
                        max_length=32,
                    ),
                ),
                (
                    "handle",
                    models.CharField(
                        help_text="Bluesky handle that should resolve to Arthexis. Use the verified domain (for example arthexis.com).",
                        max_length=253,
                        validators=[
                            django.core.validators.RegexValidator(
                                code="invalid",
                                message="Enter a valid domain name such as example.com.",
                                regex=re.compile(
                                    "^(?=.{1,253}\\Z)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*$"
                                ),
                            )
                        ],
                    ),
                ),
                (
                    "domain",
                    models.CharField(
                        help_text="Domain that hosts the Bluesky verification. Publish a _atproto TXT record or a /.well-known/atproto-did file with the DID below.",
                        max_length=253,
                        validators=[
                            django.core.validators.RegexValidator(
                                code="invalid",
                                message="Enter a valid domain name such as example.com.",
                                regex=re.compile(
                                    "^(?=.{1,253}\\Z)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*$"
                                ),
                            )
                        ],
                    ),
                ),
                (
                    "did",
                    models.CharField(
                        blank=True,
                        help_text="Optional DID that Bluesky assigns once the domain is linked (for example did:plc:1234abcd).",
                        max_length=255,
                        validators=[
                            django.core.validators.RegexValidator(
                                code="invalid",
                                message="Enter a valid DID such as did:plc:1234abcd.",
                                regex="^(|did:[a-z0-9]+:[A-Za-z0-9.\\-_:]+)$",
                            )
                        ],
                    ),
                ),
                (
                    "group",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to="core.securitygroup",
                    ),
                ),
                (
                    "user",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Social Profile",
                "verbose_name_plural": "Social Profiles",
                "constraints": [
                    models.UniqueConstraint(
                        fields=("network", "handle"),
                        name="socialprofile_network_handle",
                    ),
                    models.UniqueConstraint(
                        fields=("network", "domain"),
                        name="socialprofile_network_domain",
                    ),
                    models.CheckConstraint(
                        condition=models.Q(
                            models.Q(("user__isnull", False), ("group__isnull", True)),
                            models.Q(("user__isnull", True), ("group__isnull", False)),
                            _connector="OR",
                        ),
                        name="socialprofile_requires_owner",
                    ),
                ],
            },
        ),
    ]
