# Generated by Django 5.2.9 on 2025-12-17 19:21

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("groups", "0002_initial"),
        ("maps", "0002_initial"),
        ("nodes", "0007_node_base_site"),
        ("odoo", "0005_odoodeployment_base_path"),
        ("tasks", "0002_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="ManualSkill",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                ("name", models.CharField(max_length=200, verbose_name="Name")),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Optional details supporting Markdown formatting.",
                        verbose_name="Description",
                    ),
                ),
            ],
            options={
                "verbose_name": "Manual Skill",
                "verbose_name_plural": "Manual Skills",
                "db_table": "core_manualskill",
                "ordering": ("name",),
            },
        ),
        migrations.CreateModel(
            name="ManualTaskRequest",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "description",
                    models.TextField(
                        help_text="Detailed summary of the work to perform.",
                        verbose_name="Requestor Comments",
                    ),
                ),
                (
                    "duration",
                    models.DurationField(
                        blank=True,
                        help_text="Estimated time to complete the task.",
                        null=True,
                        verbose_name="Expected duration",
                    ),
                ),
                (
                    "scheduled_start",
                    models.DateTimeField(
                        help_text="Planned start time for this work.",
                        verbose_name="Scheduled start",
                    ),
                ),
                (
                    "scheduled_end",
                    models.DateTimeField(
                        help_text="Planned completion time for this work.",
                        verbose_name="Scheduled end",
                    ),
                ),
                (
                    "is_periodic",
                    models.BooleanField(
                        default=False,
                        help_text="Whether this request should repeat on a schedule.",
                        verbose_name="Is periodic",
                    ),
                ),
                (
                    "period",
                    models.DurationField(
                        blank=True,
                        help_text="Length of each execution window when periodic.",
                        null=True,
                        verbose_name="Period",
                    ),
                ),
                (
                    "period_deadline",
                    models.DurationField(
                        blank=True,
                        help_text="Optional cutoff within each period when the schedule resets for the next cycle.",
                        null=True,
                        verbose_name="Period deadline",
                    ),
                ),
                (
                    "enable_notifications",
                    models.BooleanField(
                        default=False,
                        help_text="Send reminder emails to the assigned contacts when Celery notifications are available.",
                        verbose_name="Enable notifications",
                    ),
                ),
                (
                    "assigned_group",
                    models.ForeignKey(
                        blank=True,
                        help_text="Security group containing users who can fulfill the task.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_manual_task_requests",
                        to="groups.securitygroup",
                        verbose_name="Potential assignees",
                    ),
                ),
                (
                    "assigned_user",
                    models.ForeignKey(
                        blank=True,
                        help_text="Optional user responsible for coordinating the task.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_manual_task_requests",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Assigned user",
                    ),
                ),
                (
                    "category",
                    models.ForeignKey(
                        blank=True,
                        help_text="Select the standardized category for this work.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="manual_task_requests",
                        to="tasks.taskcategory",
                        verbose_name="Category",
                    ),
                ),
                (
                    "location",
                    models.ForeignKey(
                        blank=True,
                        help_text="Location associated with this manual task.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="manual_task_requests",
                        to="maps.location",
                        verbose_name="Location",
                    ),
                ),
                (
                    "manager",
                    models.ForeignKey(
                        blank=True,
                        help_text="User overseeing the task.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="managed_manual_task_requests",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Manager",
                    ),
                ),
                (
                    "node",
                    models.ForeignKey(
                        blank=True,
                        help_text="Node where this manual task should be completed.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="manual_task_requests",
                        to="nodes.node",
                        verbose_name="Node",
                    ),
                ),
                (
                    "odoo_products",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Products associated with the requested work.",
                        related_name="manual_task_requests",
                        to="odoo.odooproduct",
                        verbose_name="Odoo products",
                    ),
                ),
                (
                    "requestor",
                    models.ForeignKey(
                        blank=True,
                        help_text="User creating the manual task request.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="requested_manual_tasks",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Requestor",
                    ),
                ),
                (
                    "required_skills",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Optional skills that should cover this request.",
                        related_name="manual_task_requests",
                        to="tasks.manualskill",
                        verbose_name="Required skills",
                    ),
                ),
            ],
            options={
                "verbose_name": "Manual Task Request",
                "verbose_name_plural": "Manual Task Requests",
                "db_table": "core_manualtaskrequest",
                "ordering": ("scheduled_start", "category__name"),
            },
        ),
        migrations.CreateModel(
            name="ManualTaskReport",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "performed_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When the work occurred.",
                        verbose_name="Performed at",
                    ),
                ),
                (
                    "duration",
                    models.DurationField(
                        blank=True,
                        help_text="Actual time spent completing the task.",
                        null=True,
                        verbose_name="Actual duration",
                    ),
                ),
                (
                    "details",
                    models.TextField(
                        help_text="Executor notes and outcomes for this task.",
                        verbose_name="Details",
                    ),
                ),
                (
                    "executor",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who performed the work. Can differ from the assignee.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="executed_manual_task_reports",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Executor",
                    ),
                ),
                (
                    "request",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reports",
                        to="tasks.manualtaskrequest",
                        verbose_name="Task request",
                    ),
                ),
            ],
            options={
                "verbose_name": "Manual Task Report",
                "verbose_name_plural": "Manual Task Reports",
                "db_table": "core_manualtaskreport",
                "ordering": ("-performed_at",),
            },
        ),
        migrations.DeleteModel(
            name="ManualTask",
        ),
        migrations.AddConstraint(
            model_name="manualtaskrequest",
            constraint=models.CheckConstraint(
                condition=models.Q(
                    ("node__isnull", False),
                    ("location__isnull", False),
                    _connector="OR",
                ),
                name="manualtaskrequest_requires_target",
            ),
        ),
        migrations.AddConstraint(
            model_name="manualtaskrequest",
            constraint=models.CheckConstraint(
                condition=models.Q(("scheduled_end__gte", models.F("scheduled_start"))),
                name="manualtaskrequest_schedule_order",
            ),
        ),
    ]
