# Generated by Django 5.2.8 on 2025-12-02 09:51

from decimal import Decimal

import django.core.validators
import django.db.models.deletion
import rules.contrib.models
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0015_add_hide_expert_mode_to_service_definition"),
    ]

    operations = [
        migrations.CreateModel(
            name="ComputePlan",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Last updated"),
                ),
                ("name", models.CharField(max_length=100, verbose_name="Name")),
                (
                    "description",
                    models.TextField(blank=True, verbose_name="Description"),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="Whether this plan is available for selection",
                        verbose_name="Is active",
                    ),
                ),
                (
                    "memory_requests",
                    models.CharField(
                        max_length=20,
                        verbose_name="Memory requests",
                    ),
                ),
                (
                    "memory_limits",
                    models.CharField(
                        max_length=20,
                        verbose_name="Memory limits",
                    ),
                ),
                (
                    "cpu_requests",
                    models.CharField(
                        max_length=20,
                        verbose_name="CPU requests",
                    ),
                ),
                (
                    "cpu_limits",
                    models.CharField(
                        max_length=20,
                        verbose_name="CPU limits",
                    ),
                ),
            ],
            options={
                "verbose_name": "Compute Plan",
                "verbose_name_plural": "Compute Plans",
                "ordering": ["name"],
            },
            bases=(rules.contrib.models.RulesModelMixin, models.Model),
        ),
        migrations.AddField(
            model_name="controlplane",
            name="storage_plan_odoo_product_id",
            field=models.IntegerField(
                blank=True,
                help_text="ID of the storage product in Odoo",
                null=True,
                verbose_name="Storage plan Odoo product ID",
            ),
        ),
        migrations.AddField(
            model_name="controlplane",
            name="storage_plan_odoo_unit_id",
            field=models.IntegerField(
                blank=True,
                help_text="ID of the unit of measure in Odoo (uom.uom)",
                null=True,
                verbose_name="Storage plan Odoo unit ID",
            ),
        ),
        migrations.AddField(
            model_name="controlplane",
            name="storage_plan_price_per_gib",
            field=models.DecimalField(
                blank=True,
                decimal_places=2,
                help_text="Price per GiB of storage",
                max_digits=10,
                null=True,
                verbose_name="Storage plan price per GiB",
            ),
        ),
        migrations.CreateModel(
            name="ComputePlanAssignment",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Last updated"),
                ),
                (
                    "sla",
                    models.CharField(
                        choices=[
                            ("besteffort", "Best Effort"),
                            ("guaranteed", "Guaranteed Availability"),
                        ],
                        help_text="Service Level Agreement",
                        max_length=20,
                        verbose_name="SLA",
                    ),
                ),
                (
                    "odoo_product_id",
                    models.IntegerField(
                        help_text="ID of the product in Odoo (product.product or product.template)",
                        verbose_name="Odoo product ID",
                    ),
                ),
                (
                    "odoo_unit_id",
                    models.IntegerField(
                        help_text="ID of the unit of measure in Odoo (uom.uom)",
                        verbose_name="Odoo unit ID",
                    ),
                ),
                (
                    "price",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Price per unit",
                        max_digits=10,
                        validators=[
                            django.core.validators.MinValueValidator(Decimal("0.00"))
                        ],
                        verbose_name="Price",
                    ),
                ),
                (
                    "minimum_service_size",
                    models.PositiveIntegerField(
                        default=1,
                        help_text="Minimum value for spec.parameters.instances (Guaranteed Availability may require multiple instances)",
                        validators=[django.core.validators.MinValueValidator(1)],
                        verbose_name="Minimum service size",
                    ),
                ),
                (
                    "sort_order",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Order in which plans are displayed to users",
                        verbose_name="Sort order",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="Whether this plan is available for this CRD",
                        verbose_name="Is active",
                    ),
                ),
                (
                    "compute_plan",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="assignments",
                        to="core.computeplan",
                        verbose_name="Compute plan",
                    ),
                ),
                (
                    "control_plane_crd",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="compute_plan_assignments",
                        to="core.controlplanecrd",
                        verbose_name="Control plane CRD",
                    ),
                ),
            ],
            options={
                "verbose_name": "Compute Plan Assignment",
                "verbose_name_plural": "Compute Plan Assignments",
                "ordering": ["sort_order", "compute_plan__name", "sla"],
                "unique_together": {("compute_plan", "control_plane_crd", "sla")},
            },
            bases=(rules.contrib.models.RulesModelMixin, models.Model),
        ),
        migrations.AddField(
            model_name="serviceinstance",
            name="compute_plan_assignment",
            field=models.ForeignKey(
                blank=True,
                help_text="Compute plan with SLA for this instance",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="instances",
                to="core.computeplanassignment",
                verbose_name="Compute plan assignment",
            ),
        ),
        migrations.CreateModel(
            name="OdooObjectCache",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Last updated"),
                ),
                (
                    "odoo_model",
                    models.CharField(
                        help_text="Odoo model name: 'product.product', 'product.template', 'uom.uom', etc.",
                        max_length=100,
                        verbose_name="Odoo model",
                    ),
                ),
                (
                    "odoo_id",
                    models.PositiveIntegerField(
                        help_text="ID in the Odoo model", verbose_name="Odoo ID"
                    ),
                ),
                (
                    "data",
                    models.JSONField(
                        help_text="Cached Odoo data including price, reporting_product_id, etc.",
                        verbose_name="Cached data",
                    ),
                ),
                (
                    "expires_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="When cache should be refreshed (null = never expires)",
                        null=True,
                        verbose_name="Expires at",
                    ),
                ),
            ],
            options={
                "verbose_name": "Odoo Object Cache",
                "verbose_name_plural": "Odoo Object Caches",
                "indexes": [
                    models.Index(
                        fields=["odoo_model", "odoo_id"],
                        name="core_odooob_odoo_mo_51e258_idx",
                    ),
                    models.Index(
                        fields=["expires_at"], name="core_odooob_expires_8fc00b_idx"
                    ),
                ],
                "unique_together": {("odoo_model", "odoo_id")},
            },
            bases=(rules.contrib.models.RulesModelMixin, models.Model),
        ),
    ]
