# Generated by Django 5.1.3 on 2026-06-01 08:01

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("bpm", "0001_initial"),
        ("tenants", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ProcessDefinition",
            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",
                    ),
                ),
                (
                    "hierarchy_id",
                    models.CharField(
                        help_text='Dot-notation identifier, e.g. "1.1.1".',
                        max_length=64,
                        verbose_name="hierarchy ID",
                    ),
                ),
                (
                    "level",
                    models.PositiveSmallIntegerField(
                        default=1,
                        help_text="1=Category, 2=Process Group, 3=Process, 4=Activity.",
                        verbose_name="level",
                    ),
                ),
                ("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")),
                (
                    "trigger",
                    models.TextField(
                        blank=True,
                        help_text="Event or condition that initiates this process.",
                        verbose_name="trigger",
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "Draft"),
                            ("active", "Active"),
                            ("deprecated", "Deprecated"),
                            ("archived", "Archived"),
                        ],
                        db_index=True,
                        default="draft",
                        max_length=16,
                        verbose_name="status",
                    ),
                ),
                (
                    "version",
                    models.CharField(
                        default="1.0",
                        help_text='Semantic version string, e.g. "1.0", "2.3".',
                        max_length=32,
                        verbose_name="version",
                    ),
                ),
                (
                    "effective_date",
                    models.DateField(blank=True, null=True, verbose_name="effective date"),
                ),
                (
                    "review_date",
                    models.DateField(blank=True, null=True, verbose_name="review date"),
                ),
            ],
            options={
                "verbose_name": "process definition",
                "verbose_name_plural": "process definitions",
                "ordering": ["hierarchy_id"],
            },
        ),
        migrations.CreateModel(
            name="ProcessDocument",
            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")),
                (
                    "dms_document_id",
                    models.UUIDField(
                        help_text="UUID matching dms.Document.public_id.",
                        verbose_name="DMS document ID",
                    ),
                ),
                (
                    "doc_type",
                    models.CharField(
                        choices=[
                            ("procedure", "Procedure"),
                            ("form", "Form"),
                            ("template", "Template"),
                            ("policy", "Policy"),
                            ("guideline", "Guideline"),
                            ("other", "Other"),
                        ],
                        default="procedure",
                        max_length=16,
                        verbose_name="document type",
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        blank=True,
                        help_text="Cached document title for quick display without a DMS lookup.",
                        max_length=512,
                        verbose_name="title",
                    ),
                ),
                ("notes", models.TextField(blank=True, verbose_name="notes")),
            ],
            options={
                "verbose_name": "process document",
                "verbose_name_plural": "process documents",
                "ordering": ["doc_type", "title"],
            },
        ),
        migrations.CreateModel(
            name="ProcessOwnership",
            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")),
                (
                    "role",
                    models.CharField(
                        choices=[
                            ("owner", "Process Owner"),
                            ("manager", "Process Manager"),
                            ("reviewer", "Reviewer"),
                            ("approver", "Approver"),
                        ],
                        default="owner",
                        max_length=16,
                        verbose_name="role",
                    ),
                ),
                (
                    "assigned_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="assigned at"),
                ),
                ("notes", models.TextField(blank=True, verbose_name="notes")),
            ],
            options={
                "verbose_name": "process ownership",
                "verbose_name_plural": "process ownerships",
            },
        ),
        migrations.RenameIndex(
            model_name="pcfelement",
            new_name="bpm_pcfelem_framewo_7e6e47_idx",
            old_name="bpm_pcfelem_framew_level_idx",
        ),
        migrations.RenameIndex(
            model_name="pcfelement",
            new_name="bpm_pcfelem_framewo_b96a83_idx",
            old_name="bpm_pcfelem_framew_hier_idx",
        ),
        migrations.RenameIndex(
            model_name="pcfframework",
            new_name="bpm_pcffram_industr_ea0bbf_idx",
            old_name="bpm_pcffram_industr_idx",
        ),
        migrations.AddField(
            model_name="processdefinition",
            name="framework",
            field=models.ForeignKey(
                help_text="The PCF edition this definition is aligned with.",
                on_delete=django.db.models.deletion.PROTECT,
                related_name="process_definitions",
                to="bpm.pcfframework",
                verbose_name="PCF framework",
            ),
        ),
        migrations.AddField(
            model_name="processdefinition",
            name="parent",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="children",
                to="bpm.processdefinition",
                verbose_name="parent process",
            ),
        ),
        migrations.AddField(
            model_name="processdefinition",
            name="pcf_element",
            field=models.ForeignKey(
                blank=True,
                help_text="Standard PCF node this process maps to (optional).",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="process_definitions",
                to="bpm.pcfelement",
                verbose_name="PCF element",
            ),
        ),
        migrations.AddField(
            model_name="processdefinition",
            name="tenant",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="process_definitions",
                to="tenants.tenant",
                verbose_name="tenant",
            ),
        ),
        migrations.AddField(
            model_name="processdocument",
            name="process",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="documents",
                to="bpm.processdefinition",
                verbose_name="process",
            ),
        ),
        migrations.AddField(
            model_name="processownership",
            name="process",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="ownerships",
                to="bpm.processdefinition",
                verbose_name="process",
            ),
        ),
        migrations.AddField(
            model_name="processownership",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="process_ownerships",
                to=settings.AUTH_USER_MODEL,
                verbose_name="user",
            ),
        ),
        migrations.AddIndex(
            model_name="processdefinition",
            index=models.Index(fields=["tenant", "status"], name="bpm_process_tenant__6d3ebb_idx"),
        ),
        migrations.AddIndex(
            model_name="processdefinition",
            index=models.Index(
                fields=["tenant", "framework"], name="bpm_process_tenant__afbc4a_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="processdefinition",
            constraint=models.UniqueConstraint(
                fields=("tenant", "hierarchy_id"),
                name="bpm_processdefinition_unique_tenant_hierarchy",
            ),
        ),
        migrations.AddConstraint(
            model_name="processdocument",
            constraint=models.UniqueConstraint(
                fields=("process", "dms_document_id"), name="bpm_processdocument_unique_process_doc"
            ),
        ),
        migrations.AddConstraint(
            model_name="processownership",
            constraint=models.UniqueConstraint(
                fields=("process", "user", "role"),
                name="bpm_processownership_unique_process_user_role",
            ),
        ),
    ]
