# Generated by Django 5.1.2 on 2024-12-18 22:25

import django.core.serializers.json
import django.core.validators
import django.db.models.deletion
import kitchenai.django_webhook.validators
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="Webhook",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("url", models.URLField()),
                ("active", models.BooleanField(default=True)),
                ("uuid", models.UUIDField(default=uuid.uuid4, editable=False)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name="WebhookTopic",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        max_length=250,
                        unique=True,
                        validators=[
                            django.core.validators.RegexValidator(
                                "\\w+\\.\\w+\\/[create|update|delete]",
                                message="Topic must match: \\w+\\.\\w+\\/[create|update|delete]",
                            ),
                            kitchenai.django_webhook.validators.validate_topic_model,
                        ],
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="WebhookEvent",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "object",
                    models.JSONField(
                        editable=False,
                        encoder=django.core.serializers.json.DjangoJSONEncoder,
                        max_length=1000,
                    ),
                ),
                (
                    "object_type",
                    models.CharField(editable=False, max_length=50, null=True),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("PENDING", "Pending"),
                            ("COMPLETED", "Completed"),
                            ("FAILED", "Failed"),
                        ],
                        default="PENDING",
                        editable=False,
                        max_length=40,
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("url", models.URLField(editable=False)),
                ("topic", models.CharField(editable=False, max_length=250, null=True)),
                (
                    "webhook",
                    models.ForeignKey(
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="events",
                        related_query_name="event",
                        to="django_webhook.webhook",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="WebhookSecret",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "token",
                    models.CharField(
                        max_length=100,
                        validators=[django.core.validators.MinLengthValidator(12)],
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                (
                    "webhook",
                    models.ForeignKey(
                        editable=False,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="secrets",
                        related_query_name="secret",
                        to="django_webhook.webhook",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="webhook",
            name="topics",
            field=models.ManyToManyField(
                related_name="webhooks",
                related_query_name="webhook",
                to="django_webhook.webhooktopic",
            ),
        ),
    ]
