# Generated by Django 4.2.23 on 2025-10-06 21:01

import NEMO.fields
import NEMO_fabublox_integration.models
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="FabubloxIntegrationConfiguration",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "instance_id",
                    models.CharField(
                        blank=True,
                        help_text="Unique identifier for this NEMO instance in Fabublox (Do not change this unless instructed by Fabublox support).",
                        max_length=255,
                        null=True,
                        unique=True,
                    ),
                ),
                (
                    "data_sync_bucket_name",
                    models.CharField(
                        blank=True,
                        help_text="Name of the bucket used for data synchronization with Fabublox (Do not change this unless instructed by Fabublox support).",
                        max_length=255,
                        null=True,
                        unique=True,
                    ),
                ),
                (
                    "admin_permission",
                    NEMO.fields.MultiRoleGroupPermissionChoiceField(
                        default="is_superuser",
                        help_text="The roles/groups required for users to access the Fabublox integration features.",
                    ),
                ),
                (
                    "shared_tool_fields",
                    models.JSONField(
                        blank=True,
                        default=NEMO_fabublox_integration.models.ToolField.get_all_fields,
                        help_text="List of fields to be shared with Fabublox for tool synchronization.",
                        null=True,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="FabubloxSynchronizationJob",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "status",
                    models.IntegerField(
                        choices=[
                            (0, "Pending"),
                            (1, "In Progress"),
                            (2, "Completed"),
                            (3, "Partially Completed"),
                            (4, "Failed"),
                        ],
                        default=0,
                        help_text="Current status of the synchronization job",
                    ),
                ),
                (
                    "total_items",
                    models.PositiveIntegerField(default=0, help_text="Total number of items to be synchronized"),
                ),
                (
                    "succeeded_items",
                    models.PositiveIntegerField(default=0, help_text="Number of items successfully synchronized"),
                ),
                (
                    "failed_items",
                    models.PositiveIntegerField(default=0, help_text="Number of items that failed to synchronize"),
                ),
                ("item_ids", models.JSONField(help_text="List of item IDs being synchronized")),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="Timestamp when the job was created")),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, help_text="Timestamp when the job was last updated"),
                ),
                (
                    "content_type",
                    models.ForeignKey(
                        help_text="Content type of the model being synced",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "started_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who started this synchronization job",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="fabublox_sync_jobs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="FabubloxSyncFailure",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("item_id", models.PositiveIntegerField(help_text="ID of the item that failed to sync")),
                ("item_name", models.CharField(help_text="Name of the item that failed", max_length=255)),
                ("error_message", models.TextField(help_text="Error message from the failed sync attempt")),
                ("failed_at", models.DateTimeField(auto_now_add=True, help_text="Timestamp when the sync failed")),
                (
                    "job",
                    models.ForeignKey(
                        help_text="Synchronization job",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="failures",
                        to="NEMO_fabublox_integration.fabubloxsynchronizationjob",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="FabubloxDataSyncStatus",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("object_id", models.PositiveIntegerField()),
                (
                    "last_synced",
                    models.DateTimeField(auto_now=True, help_text="Timestamp of the last sync attempt with FabuBlox"),
                ),
                (
                    "content_type",
                    models.ForeignKey(
                        help_text="Content type of the model being synced",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "last_synced_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who last synced this entity",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="fabublox_sync_status",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.AddIndex(
            model_name="fabubloxsynchronizationjob",
            index=models.Index(fields=["status", "-created_at"], name="NEMO_fabubl_status_9a5a01_idx"),
        ),
        migrations.AddIndex(
            model_name="fabubloxsynchronizationjob",
            index=models.Index(fields=["-created_at"], name="NEMO_fabubl_created_a9ef2a_idx"),
        ),
        migrations.AddIndex(
            model_name="fabubloxsyncfailure",
            index=models.Index(fields=["job", "-failed_at"], name="NEMO_fabubl_job_id_d062e6_idx"),
        ),
        migrations.AddIndex(
            model_name="fabubloxdatasyncstatus",
            index=models.Index(
                fields=["content_type", "object_id", "-last_synced"], name="NEMO_fabubl_content_c0441c_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="fabubloxdatasyncstatus",
            index=models.Index(fields=["-last_synced"], name="NEMO_fabubl_last_sy_323f0c_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="fabubloxdatasyncstatus",
            unique_together={("content_type", "object_id")},
        ),
    ]
