# Generated by Django 5.0.6 on 2024-05-24 22:11

from django.db import migrations, models

import cool_urls.logging


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="CoolUrl",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "url",
                    models.URLField(
                        editable=False,
                        unique=True,
                    ),
                ),
                (
                    "is_ready",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        editable=False,
                    ),
                ),
                (
                    "is_processing",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        editable=False,
                    ),
                ),
                (
                    "is_failed",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        editable=False,
                    ),
                ),
                (
                    "archived_at",
                    models.DateTimeField(
                        blank=True,
                        db_index=True,
                        editable=False,
                        null=True,
                    ),
                ),
                (
                    "show_local",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        help_text=(
                            "Whether we want to use the local copy or "
                            "continue to refer to the remote one."
                        ),
                    ),
                ),
                (
                    "is_embedded",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        editable=False,
                        help_text=(
                            "If this is true, we'll attempt to pull down the "
                            "audio or video from the page so it can be "
                            "embedded rather than a copy of the page itself."
                        ),
                    ),
                ),
                (
                    "last_http_check_state",
                    models.PositiveIntegerField(
                        blank=True,
                        db_index=True,
                        editable=False,
                        null=True,
                    ),
                ),
                (
                    "last_http_check_time",
                    models.DateTimeField(
                        blank=True,
                        db_index=True,
                        editable=False,
                        null=True,
                    ),
                ),
            ],
            options={
                "verbose_name": "Cool URL",
                "verbose_name_plural": "Cool URLs",
            },
            bases=(cool_urls.logging.Loggable, models.Model),
        ),
        migrations.AddConstraint(
            model_name="coolurl",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("is_failed", False),
                        ("is_processing", False),
                        ("is_ready", True),
                    ),
                    models.Q(
                        ("is_failed", False),
                        ("is_processing", True),
                        ("is_ready", False),
                    ),
                    models.Q(
                        ("is_failed", True),
                        ("is_processing", False),
                        ("is_ready", False),
                    ),
                    models.Q(
                        ("is_failed", False),
                        ("is_processing", False),
                        ("is_ready", False),
                    ),
                    _connector="OR",
                ),
                name="coolurl_status_permutations",
            ),
        ),
        migrations.AddConstraint(
            model_name="coolurl",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("archived_at__isnull", False),
                        ("is_ready", True),
                    ),
                    models.Q(
                        ("archived_at__isnull", True),
                        ("is_ready", False),
                    ),
                    _connector="OR",
                ),
                name="coolurl_archived_at_vs_ready",
            ),
        ),
    ]
