# Generated by Django 5.2.10 on 2026-01-19 21:09

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("accounts", "0004_populate_existing_users_onboarding"),
        ("integrations", "0001_initial"),
        ("sources", "0001_initial"),
    ]

    operations = [
        migrations.AlterField(
            model_name="githubinstallation",
            name="account_avatar_url",
            field=models.URLField(blank=True, default="", max_length=500),
        ),
        migrations.CreateModel(
            name="LinkedInPage",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "organization_urn",
                    models.CharField(
                        help_text="LinkedIn org URN (urn:li:organization:123)",
                        max_length=100,
                    ),
                ),
                (
                    "organization_id",
                    models.CharField(
                        db_index=True,
                        help_text="Numeric org ID extracted from URN",
                        max_length=50,
                    ),
                ),
                (
                    "name",
                    models.CharField(help_text="Organization display name", max_length=255),
                ),
                (
                    "vanity_name",
                    models.CharField(blank=True, help_text="LinkedIn vanity URL slug", max_length=100),
                ),
                (
                    "logo_url",
                    models.URLField(blank=True, help_text="Organization logo URL", max_length=500),
                ),
                (
                    "_access_token",
                    models.TextField(blank=True, db_column="access_token"),
                ),
                (
                    "_refresh_token",
                    models.TextField(blank=True, db_column="refresh_token"),
                ),
                ("token_expires_at", models.DateTimeField(blank=True, null=True)),
                (
                    "authorized_user_urn",
                    models.CharField(
                        blank=True,
                        help_text="URN of user who authorized",
                        max_length=100,
                    ),
                ),
                (
                    "sync_status",
                    models.CharField(
                        choices=[
                            ("PENDING", "Pending"),
                            ("ACTIVE", "Active"),
                            ("SYNCING", "Syncing"),
                            ("ERROR", "Error"),
                            ("PAUSED", "Paused"),
                            ("EXPIRED", "Expired"),
                        ],
                        default="PENDING",
                        max_length=20,
                    ),
                ),
                (
                    "sync_error",
                    models.TextField(blank=True, help_text="Last sync error message"),
                ),
                ("last_sync_at", models.DateTimeField(blank=True, null=True)),
                ("next_sync_at", models.DateTimeField(blank=True, null=True)),
                (
                    "sync_interval_minutes",
                    models.IntegerField(default=15, help_text="Polling interval in minutes"),
                ),
                (
                    "sync_cursors",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Sync state and pagination cursors",
                    ),
                ),
                ("is_archived", models.BooleanField(default=False)),
                (
                    "source",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="linkedin_page",
                        to="sources.source",
                    ),
                ),
                (
                    "workspace",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="linkedin_pages",
                        to="accounts.workspace",
                    ),
                ),
            ],
            options={
                "verbose_name": "LinkedIn Page",
                "verbose_name_plural": "LinkedIn Pages",
                "indexes": [
                    models.Index(
                        fields=["organization_id"],
                        name="integration_organiz_e5a58e_idx",
                    ),
                    models.Index(fields=["sync_status"], name="integration_sync_st_daaaa5_idx"),
                    models.Index(fields=["next_sync_at"], name="integration_next_sy_695198_idx"),
                    models.Index(fields=["is_archived"], name="integration_is_arch_8311b7_idx"),
                ],
                "constraints": [
                    models.UniqueConstraint(
                        condition=models.Q(("is_archived", False)),
                        fields=("workspace", "organization_urn"),
                        name="unique_active_linkedin_page_per_workspace",
                    )
                ],
            },
        ),
    ]
