# SPDX-FileCopyrightText: 2022-2025 Helmholtz-Zentrum hereon GmbH
#
# SPDX-License-Identifier: EUPL-1.2

# Generated by Django 3.2.15 on 2023-01-09 20:42

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="BrokerTopic",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "slug",
                    models.SlugField(
                        help_text="Unique identifier for the topic.",
                        unique=True,
                    ),
                ),
                (
                    "is_public",
                    models.BooleanField(
                        default=False,
                        help_text="Can everyone publish data to this topic?",
                    ),
                ),
                (
                    "date_created",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="The date and time when the message has been created",
                    ),
                ),
            ],
            options={
                "permissions": (
                    (
                        "can_produce",
                        "Can publish messages to the topic (Producer).",
                    ),
                    (
                        "can_consume",
                        "Can consume messages to the topic (Consumer).",
                    ),
                ),
            },
        ),
        migrations.CreateModel(
            name="BrokerMessage",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "message_id",
                    models.UUIDField(db_index=True, help_text="Message ID"),
                ),
                (
                    "context",
                    models.IntegerField(
                        blank=True,
                        help_text="Message context for messages from a producer.",
                        null=True,
                    ),
                ),
                (
                    "content",
                    models.JSONField(help_text="The content of the message."),
                ),
                (
                    "delivered",
                    models.BooleanField(
                        default=False,
                        help_text="Has this message already been delivered?",
                    ),
                ),
                (
                    "date_created",
                    models.DateTimeField(
                        help_text="The date and time when the message has been created"
                    ),
                ),
                (
                    "topic",
                    models.ForeignKey(
                        help_text="The topic the message was published for.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="dasf_broker.brokertopic",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="The user who produced the message.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ResponseTopic",
            fields=[
                (
                    "brokertopic_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="dasf_broker.brokertopic",
                    ),
                ),
                (
                    "is_response_for",
                    models.ForeignKey(
                        blank=True,
                        help_text="Is this topic used only once for a single response?",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="responsetopics",
                        to="dasf_broker.brokertopic",
                    ),
                ),
                (
                    "source_messages",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Messages from the producer to the reference topic.",
                        to="dasf_broker.BrokerMessage",
                    ),
                ),
            ],
            bases=("dasf_broker.brokertopic",),
        ),
        migrations.AddConstraint(
            model_name="brokermessage",
            constraint=models.UniqueConstraint(
                fields=("message_id", "topic"),
                name="unique_message_id_for_topic",
            ),
        ),
    ]
