# Generated by Django 4.2.13 on 2024-06-08 17:40

import uuid

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

import catalog.common.utils


class Migration(migrations.Migration):
    """
    This migration is a combination of all the migrations til 0.10.0
    """

    replaces = [
        ("catalog", "0001_initial"),
        ("catalog", "0002_initial"),
        ("catalog", "0003_podcast"),
        ("catalog", "0004_podcast_no_real_change"),
        ("catalog", "0005_bookstw"),
        ("catalog", "0006_auto_20230602_0258"),
        ("catalog", "0007_performance"),
        ("catalog", "0008_delete_historicalitem"),
        ("catalog", "0009_remove_tvepisode_show"),
        ("catalog", "0010_alter_item_polymorphic_ctype"),
        ("catalog", "0011_remove_item_last_editor"),
        ("catalog", "0011_alter_externalresource_id_type_and_more"),
        ("catalog", "0012_alter_model_i18n"),
    ]
    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
    ]

    operations = [
        migrations.CreateModel(
            name="Item",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "uid",
                    models.UUIDField(db_index=True, default=uuid.uuid4, editable=False),
                ),
                (
                    "title",
                    models.CharField(default="", max_length=1000, verbose_name="title"),
                ),
                (
                    "brief",
                    models.TextField(
                        blank=True, default="", verbose_name="description"
                    ),
                ),
                (
                    "primary_lookup_id_type",
                    models.CharField(
                        max_length=50, null=True, verbose_name="Primary ID Type"
                    ),
                ),
                (
                    "primary_lookup_id_value",
                    models.CharField(
                        help_text="automatically detected, usually no change necessary, left empty if unsure",
                        max_length=1000,
                        null=True,
                        verbose_name="Primary ID Value",
                    ),
                ),
                (
                    "metadata",
                    models.JSONField(
                        blank=True, default=dict, null=True, verbose_name="metadata"
                    ),
                ),
                (
                    "cover",
                    models.ImageField(
                        blank=True,
                        default="item/default.svg",
                        upload_to=catalog.common.utils.item_cover_path,
                        verbose_name="cover",
                    ),
                ),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                ("is_deleted", models.BooleanField(db_index=True, default=False)),
                (
                    "merged_to_item",
                    models.ForeignKey(
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="merged_from_items",
                        to="catalog.item",
                    ),
                ),
                (
                    "polymorphic_ctype",
                    models.ForeignKey(
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="polymorphic_%(app_label)s.%(class)s_set+",
                        to="contenttypes.contenttype",
                    ),
                ),
            ],
            options={
                "index_together": {
                    ("primary_lookup_id_type", "primary_lookup_id_value")
                },
            },
        ),
        migrations.CreateModel(
            name="Album",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Collection",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Edition",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Game",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Movie",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Podcast",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="TVShow",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
                (
                    "season_count",
                    models.IntegerField(
                        blank=True, null=True, verbose_name="number of seasons"
                    ),
                ),
                (
                    "episode_count",
                    models.PositiveIntegerField(
                        blank=True, null=True, verbose_name="number of episodes"
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Series",
            fields=[],
            options={
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="Work",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
                (
                    "editions",
                    models.ManyToManyField(related_name="works", to="catalog.edition"),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="TVSeason",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
                (
                    "season_number",
                    models.PositiveIntegerField(
                        null=True, verbose_name="season number"
                    ),
                ),
                (
                    "episode_count",
                    models.PositiveIntegerField(
                        null=True, verbose_name="number of episodes"
                    ),
                ),
                (
                    "show",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="seasons",
                        to="catalog.tvshow",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="TVEpisode",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
                ("episode_number", models.PositiveIntegerField(null=True)),
                (
                    "season",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="episodes",
                        to="catalog.tvseason",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="PodcastEpisode",
            fields=[
                ("description_html", models.TextField(null=True)),
                ("cover_url", models.CharField(max_length=1000, null=True)),
                ("media_url", models.CharField(max_length=1000, null=True)),
                ("guid", models.CharField(max_length=1000, null=True)),
                (
                    "pub_date",
                    models.DateTimeField(
                        help_text="yyyy/mm/dd hh:mm", verbose_name="date of publication"
                    ),
                ),
                ("duration", models.PositiveIntegerField(null=True)),
                (
                    "program",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="episodes",
                        to="catalog.podcast",
                    ),
                ),
                ("link", models.CharField(max_length=1000, null=True)),
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "unique_together": {("program", "guid")},
                "index_together": {("program", "pub_date")},
            },
        ),
        migrations.CreateModel(
            name="ExternalResource",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "id_type",
                    models.CharField(
                        choices=[
                            ("wikidata", "WikiData"),
                            ("isbn10", "ISBN10"),
                            ("isbn", "ISBN"),
                            ("asin", "ASIN"),
                            ("issn", "ISSN"),
                            ("cubn", "CUBN"),
                            ("isrc", "ISRC"),
                            ("gtin", "GTIN UPC EAN"),
                            ("rss", "RSS Feed URL"),
                            ("imdb", "IMDb"),
                            ("tmdb_tv", "TMDB TV Serie"),
                            ("tmdb_tvseason", "TMDB TV Season"),
                            ("tmdb_tvepisode", "TMDB TV Episode"),
                            ("tmdb_movie", "TMDB Movie"),
                            ("goodreads", "Goodreads"),
                            ("goodreads_work", "Goodreads Work"),
                            ("googlebooks", "Google Books"),
                            ("doubanbook", "Douban Book"),
                            ("doubanbook_work", "Douban Book Work"),
                            ("doubanmovie", "Douban Movie"),
                            ("doubanmusic", "Douban Music"),
                            ("doubangame", "Douban Game"),
                            ("doubandrama", "Douban Drama"),
                            ("doubandrama_version", "Douban Drama Version"),
                            ("bookstw", "BooksTW Book"),
                            ("bandcamp", "Bandcamp"),
                            ("spotify_album", "Spotify Album"),
                            ("spotify_show", "Spotify Podcast"),
                            ("discogs_release", "Discogs Release"),
                            ("discogs_master", "Discogs Master"),
                            ("musicbrainz", "MusicBrainz ID"),
                            ("igdb", "IGDB Game"),
                            ("bgg", "BGG Boardgame"),
                            ("steam", "Steam Game"),
                            ("bangumi", "Bangumi"),
                            ("apple_podcast", "Apple Podcast"),
                            ("apple_music", "Apple Music"),
                            ("fedi", "Fediverse"),
                        ],
                        max_length=50,
                        verbose_name="IdType of the source site",
                    ),
                ),
                (
                    "id_value",
                    models.CharField(
                        max_length=1000, verbose_name="Primary Id on the source site"
                    ),
                ),
                (
                    "url",
                    models.CharField(
                        max_length=1000, unique=True, verbose_name="url to the resource"
                    ),
                ),
                (
                    "cover",
                    models.ImageField(
                        blank=True,
                        default="item/default.svg",
                        upload_to=catalog.common.utils.resource_cover_path,
                    ),
                ),
                ("other_lookup_ids", models.JSONField(default=dict)),
                ("metadata", models.JSONField(default=dict)),
                ("scraped_time", models.DateTimeField(null=True)),
                ("created_time", models.DateTimeField(auto_now_add=True)),
                ("edited_time", models.DateTimeField(auto_now=True)),
                (
                    "item",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="external_resources",
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "unique_together": {("id_type", "id_value")},
            },
        ),
        migrations.CreateModel(
            name="ItemLookupId",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "id_type",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("wikidata", "WikiData"),
                            ("isbn10", "ISBN10"),
                            ("isbn", "ISBN"),
                            ("asin", "ASIN"),
                            ("issn", "ISSN"),
                            ("cubn", "CUBN"),
                            ("isrc", "ISRC"),
                            ("gtin", "GTIN UPC EAN"),
                            ("rss", "RSS Feed URL"),
                            ("imdb", "IMDb"),
                            ("tmdb_tv", "TMDB TV Serie"),
                            ("tmdb_tvseason", "TMDB TV Season"),
                            ("tmdb_tvepisode", "TMDB TV Episode"),
                            ("tmdb_movie", "TMDB Movie"),
                            ("goodreads", "Goodreads"),
                            ("goodreads_work", "Goodreads Work"),
                            ("googlebooks", "Google Books"),
                            ("doubanbook", "Douban Book"),
                            ("doubanbook_work", "Douban Book Work"),
                            ("doubanmovie", "Douban Movie"),
                            ("doubanmusic", "Douban Music"),
                            ("doubangame", "Douban Game"),
                            ("doubandrama", "Douban Drama"),
                            ("doubandrama_version", "Douban Drama Version"),
                            ("bookstw", "BooksTW Book"),
                            ("bandcamp", "Bandcamp"),
                            ("spotify_album", "Spotify Album"),
                            ("spotify_show", "Spotify Podcast"),
                            ("discogs_release", "Discogs Release"),
                            ("discogs_master", "Discogs Master"),
                            ("musicbrainz", "MusicBrainz ID"),
                            ("igdb", "IGDB Game"),
                            ("bgg", "BGG Boardgame"),
                            ("steam", "Steam Game"),
                            ("bangumi", "Bangumi"),
                            ("apple_podcast", "Apple Podcast"),
                            ("apple_music", "Apple Music"),
                            ("fedi", "Fediverse"),
                        ],
                        max_length=50,
                        verbose_name="source site",
                    ),
                ),
                (
                    "id_value",
                    models.CharField(
                        blank=True, max_length=1000, verbose_name="ID on source site"
                    ),
                ),
                (
                    "raw_url",
                    models.CharField(
                        blank=True,
                        max_length=1000,
                        unique=True,
                        verbose_name="source url",
                    ),
                ),
                (
                    "item",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="lookup_ids",
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "unique_together": {("id_type", "id_value")},
            },
        ),
        migrations.CreateModel(
            name="Performance",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
        migrations.CreateModel(
            name="PerformanceProduction",
            fields=[
                (
                    "item_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="catalog.item",
                    ),
                ),
                (
                    "show",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="productions",
                        to="catalog.performance",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("catalog.item",),
        ),
    ]
