# Generated by Django 5.1.3 on 2026-06-01 08:04

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("bpm", "0002_process_definition"),
        ("tenants", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="ProcessDataItem",
            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",
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        help_text='Short identifier, e.g. "EXT-001" or "OUT-111-1".',
                        max_length=64,
                        verbose_name="code",
                    ),
                ),
                ("name", models.CharField(max_length=512, verbose_name="name (EN)")),
                ("name_fa", models.CharField(blank=True, max_length=512, verbose_name="name (FA)")),
                ("description", models.TextField(blank=True, verbose_name="description")),
                (
                    "direction",
                    models.CharField(
                        choices=[("input", "Input"), ("output", "Output")],
                        db_index=True,
                        default="input",
                        help_text="Default direction: input (EXT) or output (OUT).",
                        max_length=8,
                        verbose_name="direction",
                    ),
                ),
                (
                    "is_external",
                    models.BooleanField(
                        default=True,
                        help_text="True for EXT items (external sources); False for OUT items (internally produced).",
                        verbose_name="is external",
                    ),
                ),
                (
                    "format",
                    models.CharField(
                        blank=True,
                        help_text='File/data format, e.g. "CSV/Excel", "PPT", "Excel + Word".',
                        max_length=128,
                        verbose_name="format",
                    ),
                ),
                (
                    "key_fields",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text='List of key data fields, e.g. ["GDP", "نرخ بهره"].',
                        verbose_name="key fields",
                    ),
                ),
                (
                    "standard_reference",
                    models.CharField(
                        blank=True,
                        help_text='Data source or standard, e.g. "IMF / بانک مرکزی".',
                        max_length=256,
                        verbose_name="standard reference",
                    ),
                ),
                (
                    "tenant",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="process_data_items",
                        to="tenants.tenant",
                        verbose_name="tenant",
                    ),
                ),
            ],
            options={
                "verbose_name": "process data item",
                "verbose_name_plural": "process data items",
                "ordering": ["direction", "code"],
            },
        ),
        migrations.CreateModel(
            name="ProcessIO",
            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")),
                (
                    "direction",
                    models.CharField(
                        choices=[("input", "Input"), ("output", "Output")],
                        db_index=True,
                        default="input",
                        max_length=8,
                        verbose_name="direction",
                    ),
                ),
                (
                    "is_required",
                    models.BooleanField(
                        default=True,
                        help_text="Whether this data item is mandatory for the process to start/complete.",
                        verbose_name="is required",
                    ),
                ),
                ("notes", models.TextField(blank=True, verbose_name="notes")),
                (
                    "data_item",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="io_links",
                        to="bpm.processdataitem",
                        verbose_name="data item",
                    ),
                ),
                (
                    "process",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="io_links",
                        to="bpm.processdefinition",
                        verbose_name="process",
                    ),
                ),
            ],
            options={
                "verbose_name": "process I/O link",
                "verbose_name_plural": "process I/O links",
                "ordering": ["direction", "data_item__code"],
            },
        ),
        migrations.CreateModel(
            name="ProcessOperationalStep",
            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")),
                (
                    "step_number",
                    models.PositiveSmallIntegerField(
                        help_text="Sequential number within the process (1-based).",
                        verbose_name="step number",
                    ),
                ),
                ("title", models.CharField(max_length=512, verbose_name="title")),
                (
                    "title_fa",
                    models.CharField(blank=True, max_length=512, verbose_name="title (FA)"),
                ),
                ("description", models.TextField(blank=True, verbose_name="description")),
                (
                    "output_description",
                    models.TextField(
                        blank=True,
                        help_text="What this step produces or delivers.",
                        verbose_name="output description",
                    ),
                ),
                (
                    "pcf_activities",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text='List of PCFElement hierarchy_ids mapped to this step, e.g. ["1.1.1.1", "1.1.1.2"].',
                        verbose_name="PCF activities",
                    ),
                ),
                (
                    "order",
                    models.PositiveSmallIntegerField(
                        db_index=True,
                        default=0,
                        help_text="Display order (may differ from step_number for re-ordering without renumbering).",
                        verbose_name="order",
                    ),
                ),
                (
                    "process",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="operational_steps",
                        to="bpm.processdefinition",
                        verbose_name="process",
                    ),
                ),
            ],
            options={
                "verbose_name": "process operational step",
                "verbose_name_plural": "process operational steps",
                "ordering": ["process", "order", "step_number"],
            },
        ),
        migrations.AddIndex(
            model_name="processdataitem",
            index=models.Index(
                fields=["tenant", "direction"], name="bpm_process_tenant__ee7ff0_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="processdataitem",
            index=models.Index(
                fields=["tenant", "is_external"], name="bpm_process_tenant__0a11a6_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="processdataitem",
            constraint=models.UniqueConstraint(
                fields=("tenant", "code"), name="bpm_processdataitem_unique_tenant_code"
            ),
        ),
        migrations.AddIndex(
            model_name="processio",
            index=models.Index(
                fields=["process", "direction"], name="bpm_process_process_b6a234_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="processio",
            constraint=models.UniqueConstraint(
                fields=("process", "data_item", "direction"),
                name="bpm_processio_unique_process_item_direction",
            ),
        ),
        migrations.AddIndex(
            model_name="processoperationalstep",
            index=models.Index(fields=["process", "order"], name="bpm_process_process_d7604d_idx"),
        ),
        migrations.AddConstraint(
            model_name="processoperationalstep",
            constraint=models.UniqueConstraint(
                fields=("process", "step_number"),
                name="bpm_processoperationalstep_unique_process_step",
            ),
        ),
    ]
