# Generated by Django 4.2.10 on 2024-02-23 11:01

import django.contrib.postgres.indexes
import django.contrib.postgres.search
import django.db.models.deletion
import mptt.fields
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("wbfdm", "0012_instrumentprice_created_instrumentprice_modified"),
    ]

    operations = [
        migrations.AddField(
            model_name="instrument",
            name="is_investable_universe",
            field=models.BooleanField(default=False),
        ),
        migrations.CreateModel(
            name="InstrumentDailyStatistics",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("statistics", models.JSONField(default=dict)),
                ("performances", models.JSONField(default=dict)),
                ("updated", models.DateTimeField(auto_now=True)),
                (
                    "instrument",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="daily_statistics",
                        to="wbfdm.instrument",
                    ),
                ),
            ],
            options={
                "verbose_name": "Daily Instrument Statistic",
                "verbose_name_plural": "Daily Instrument Statistics",
            },
        ),
        migrations.AlterField(
            model_name="instrumentprice",
            name="volume_200d",
            field=models.FloatField(
                blank=True,
                help_text="The Average Volume of the Asset over the last 200 days from the price date of the Asset.",
                null=True,
                verbose_name="Average Volume (200 Days)",
            ),
        ),
        migrations.AlterField(
            model_name="instrumentdailystatistics",
            name="performances",
            field=models.JSONField(default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
        ),
        migrations.AlterField(
            model_name="instrumentdailystatistics",
            name="statistics",
            field=models.JSONField(default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
        ),
        migrations.AddConstraint(
            model_name="classification",
            constraint=models.UniqueConstraint(fields=("group", "code_aggregated"), name="unique_classification"),
        ),
        migrations.AddConstraint(
            model_name="instrumentlistthroughmodel",
            constraint=models.UniqueConstraint(
                fields=("instrument", "instrument_list"), name="unique_instrument_per_list"
            ),
        ),
        migrations.AddConstraint(
            model_name="instrumentprice",
            constraint=models.UniqueConstraint(fields=("instrument", "date", "calculated"), name="unique_price"),
        ),
        migrations.AddField(
            model_name="instrument",
            name="level",
            field=models.PositiveIntegerField(default=0, editable=False),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="instrument",
            name="lft",
            field=models.PositiveIntegerField(default=0, editable=False),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="instrument",
            name="rght",
            field=models.PositiveIntegerField(default=0, editable=False),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="instrument",
            name="tree_id",
            field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name="instrument",
            name="parent",
            field=mptt.fields.TreeForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="children",
                to="wbfdm.instrument",
                verbose_name="Parent Instrument",
            ),
        ),
        migrations.AlterField(
            model_name="instrumentclassificationrelatedinstrument",
            name="related_instrument",
            field=models.ForeignKey(
                limit_choices_to=models.Q(("instrument_type__is_classifiable", True), ("level", 0)),
                on_delete=django.db.models.deletion.CASCADE,
                related_name="instrument_classification_related",
                to="wbfdm.instrument",
            ),
        ),
        migrations.AlterField(
            model_name="instrumentclassificationthroughmodel",
            name="instrument",
            field=models.ForeignKey(
                limit_choices_to=models.Q(("instrument_type__is_classifiable", True), ("level", 0)),
                on_delete=django.db.models.deletion.CASCADE,
                related_name="classifications_through",
                to="wbfdm.instrument",
            ),
        ),
        migrations.AlterField(
            model_name="instrumentclassificationthroughmodel",
            name="related_instruments",
            field=models.ManyToManyField(
                blank=True,
                limit_choices_to=models.Q(("instrument_type__is_classifiable", True), ("level", 0)),
                through="wbfdm.InstrumentClassificationRelatedInstrument",
                to="wbfdm.instrument",
            ),
        ),
        migrations.AddField(
            model_name="instrument",
            name="last_price_date",
            field=models.DateField(blank=True, help_text="Last Price Date", null=True, verbose_name="Last Price Date"),
        ),
        migrations.AlterField(
            model_name="instrument",
            name="is_investable_universe",
            field=models.BooleanField(
                default=False,
                help_text="If True, the instrument belongs to the investable universe",
                verbose_name="In Investable Universe",
            ),
        ),
        migrations.AlterField(
            model_name="instrumentprice",
            name="market_capitalization_consolidated",
            field=models.FloatField(
                blank=True,
                help_text="the consolidated market value of a company in local currency.",
                null=True,
                verbose_name="Market Capitalization (Consolidated)",
            ),
        ),
        migrations.AlterField(
            model_name="controversy",
            name="instrument",
            field=models.ForeignKey(
                limit_choices_to=models.Q(("level", 0)),
                on_delete=django.db.models.deletion.CASCADE,
                to="wbfdm.instrument",
            ),
        ),
        migrations.AddField(
            model_name="instrument",
            name="search_vector",
            field=django.contrib.postgres.search.SearchVectorField(null=True),
        ),
        migrations.AddField(
            model_name="instrument",
            name="trigram_search_vector",
            field=models.CharField(blank=True, max_length=1024, null=True),
        ),
        migrations.AddIndex(
            model_name="instrument",
            index=django.contrib.postgres.indexes.GinIndex(fields=["search_vector"], name="instrument_sv_gin_idx"),
        ),
        migrations.AddIndex(
            model_name="instrument",
            index=django.contrib.postgres.indexes.GinIndex(
                fields=["trigram_search_vector"], name="instrument_trigram_sv_gin_idx", opclasses=["gin_trgm_ops"]
            ),
        ),
        migrations.AddIndex(
            model_name="instrument",
            index=models.Index(fields=["parent", "exchange", "isin"], name="instrument_children_index"),
        ),
    ]
