# Generated by Django 5.1.3 on 2026-06-01 09:49

import django.db.models.deletion
import django.utils.timezone
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("bpm", "0008_process_bpmn"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="APQCBenchmark",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, db_index=True, verbose_name="created at"
                    ),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="updated at")),
                (
                    "industry",
                    models.CharField(
                        choices=[
                            ("cross_industry", "Cross Industry / کلیه صنایع"),
                            ("manufacturing", "Manufacturing / تولید"),
                            ("automotive", "Automotive / خودروسازی"),
                            ("financial", "Financial Services / خدمات مالی"),
                            ("healthcare", "Healthcare / بهداشت و درمان"),
                            ("technology", "Technology / فناوری"),
                            ("retail", "Retail / خرده\u200cفروشی"),
                            ("energy", "Energy / انرژی"),
                            ("government", "Government / دولتی"),
                            ("other", "Other / سایر"),
                        ],
                        db_index=True,
                        default="cross_industry",
                        max_length=32,
                        verbose_name="industry",
                    ),
                ),
                (
                    "year",
                    models.PositiveSmallIntegerField(db_index=True, verbose_name="benchmark year"),
                ),
                (
                    "source",
                    models.CharField(
                        blank=True,
                        default="APQC Open Standards Benchmarking",
                        max_length=256,
                        verbose_name="source",
                    ),
                ),
                ("unit", models.CharField(blank=True, max_length=64, verbose_name="unit")),
                (
                    "percentile_25",
                    models.DecimalField(
                        decimal_places=4, max_digits=18, verbose_name="25th percentile"
                    ),
                ),
                (
                    "percentile_50",
                    models.DecimalField(
                        decimal_places=4, max_digits=18, verbose_name="50th percentile (median)"
                    ),
                ),
                (
                    "percentile_75",
                    models.DecimalField(
                        decimal_places=4, max_digits=18, verbose_name="75th percentile"
                    ),
                ),
                (
                    "percentile_90",
                    models.DecimalField(
                        decimal_places=4, max_digits=18, verbose_name="90th percentile"
                    ),
                ),
                (
                    "pcf_metric",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="benchmarks",
                        to="bpm.pcfmetric",
                        verbose_name="PCF metric",
                    ),
                ),
            ],
            options={
                "verbose_name": "APQC benchmark",
                "verbose_name_plural": "APQC benchmarks",
                "ordering": ("pcf_metric", "-year", "industry"),
            },
        ),
        migrations.CreateModel(
            name="OrgBenchmarkComparison",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, db_index=True, verbose_name="created at"
                    ),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="updated at")),
                (
                    "public_id",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="public id",
                    ),
                ),
                (
                    "org_value",
                    models.DecimalField(decimal_places=4, max_digits=18, verbose_name="org value"),
                ),
                (
                    "percentile_position",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Estimated percentile (0–100) of org_value in benchmark distribution.",
                        max_digits=6,
                        null=True,
                        verbose_name="percentile position",
                    ),
                ),
                (
                    "gap_to_median",
                    models.DecimalField(
                        blank=True,
                        decimal_places=4,
                        help_text="org_value − P50. Negative = below median.",
                        max_digits=18,
                        null=True,
                        verbose_name="gap to median",
                    ),
                ),
                (
                    "assessment_date",
                    models.DateField(
                        default=django.utils.timezone.now, verbose_name="assessment date"
                    ),
                ),
                ("notes", models.TextField(blank=True, verbose_name="notes")),
                (
                    "assessed_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="bpm_benchmark_assessments",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="assessed by",
                    ),
                ),
                (
                    "benchmark",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="comparisons",
                        to="bpm.apqcbenchmark",
                        verbose_name="APQC benchmark",
                    ),
                ),
                (
                    "kpi",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="benchmark_comparisons",
                        to="bpm.processkpi",
                        verbose_name="KPI",
                    ),
                ),
                (
                    "process",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="benchmark_comparisons",
                        to="bpm.processdefinition",
                        verbose_name="process",
                    ),
                ),
            ],
            options={
                "verbose_name": "benchmark comparison",
                "verbose_name_plural": "benchmark comparisons",
                "ordering": ("-assessment_date",),
            },
        ),
        migrations.AddConstraint(
            model_name="apqcbenchmark",
            constraint=models.UniqueConstraint(
                fields=("pcf_metric", "industry", "year"),
                name="bpm_benchmark_unique_metric_industry_year",
            ),
        ),
    ]
