# Generated by Django 5.0.6 on 2024-05-27 08:56

import django.core.serializers.json
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("wbfdm", "0021_delete_instrumentdailystatistics"),
    ]

    operations = [
        migrations.CreateModel(
            name="InstrumentMetric",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("basket_id", models.PositiveIntegerField()),
                ("basket_repr", models.CharField(max_length=256)),
                (
                    "date",
                    models.DateField(
                        blank=True,
                        help_text="If date is null, the metric is considered static",
                        null=True,
                        verbose_name="Metric Date",
                    ),
                ),
                ("key", models.CharField(max_length=255, verbose_name="Metric Key")),
                (
                    "metrics",
                    models.JSONField(
                        default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder, verbose_name="Metrics"
                    ),
                ),
                (
                    "basket_content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="instrument_metrics",
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "instrument",
                    models.ForeignKey(
                        blank=True,
                        help_text="Instrument where this metric belongs to. If null, the metric is applicable to all instruments related to the basket",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="metrics",
                        to="wbfdm.instrument",
                    ),
                ),
                (
                    "parent_metric",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="dependent_metrics",
                        to="metric.instrumentmetric",
                        verbose_name="Parent Metric",
                    ),
                ),
            ],
            options={
                "verbose_name": "Instrument Metric",
                "verbose_name_plural": "Instrument Metrics",
                "indexes": [
                    models.Index(
                        fields=["basket_content_type", "basket_id", "key", "date"],
                        name="metric_inst_basket__30dcda_idx",
                    )
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="instrumentmetric",
            constraint=models.UniqueConstraint(
                fields=("basket_content_type", "basket_id", "instrument", "date", "key"),
                name="unique_instrument_metric",
            ),
        ),
    ]
