# Generated by Django 5.1.5 on 2025-01-29 08:34

import django.db.models.deletion
import hub.services.models
from django.db import migrations, models


def create_initial_currencies(apps, schema_editor):
    Currency = apps.get_model("services", "Currency")
    currencies = [
        {"code": "USD", "name": "US Dollar", "symbol": "$"},
        {"code": "CHF", "name": "Swiss Franc", "symbol": "CHF"},
        {"code": "EUR", "name": "Euro", "symbol": "€"},
    ]
    for currency_data in currencies:
        Currency.objects.create(**currency_data)


def create_initial_terms(apps, schema_editor):
    Term = apps.get_model("services", "Term")
    terms = [
        {"name": "Monthly (30d)", "order": 1},
        {"name": "Yearly", "order": 2},
        {"name": "One-time", "order": 3},
    ]
    for term_data in terms:
        Term.objects.create(**term_data)


def create_initial_categories(apps, schema_editor):
    Category = apps.get_model("services", "Category")
    categories = [
        {"name": "Database", "slug": "database", "order": 1},
        {"name": "Cache", "slug": "cache", "order": 2},
        {"name": "SaaS", "slug": "saas", "order": 3},
    ]
    for category_data in categories:
        Category.objects.create(**category_data)


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="CloudProvider",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=100)),
                ("slug", models.SlugField(unique=True)),
                ("description", models.TextField()),
                ("website", models.URLField()),
                (
                    "logo",
                    models.ImageField(
                        blank=True,
                        null=True,
                        upload_to="cloud_provider_logos/",
                        validators=[hub.services.models.validate_image_size],
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Currency",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("code", models.CharField(max_length=3, unique=True)),
                ("name", models.CharField(max_length=50)),
                ("symbol", models.CharField(max_length=5)),
            ],
            options={
                "verbose_name_plural": "Currencies",
                "ordering": ["code"],
            },
        ),
        migrations.CreateModel(
            name="Plan",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=100)),
                ("description", models.TextField()),
                ("is_default", models.BooleanField(default=False)),
                ("features", models.TextField(blank=True)),
                ("order", models.IntegerField(default=0)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "ordering": ["order", "name"],
            },
        ),
        migrations.CreateModel(
            name="Term",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=100)),
                ("description", models.TextField(blank=True)),
                ("order", models.IntegerField(default=0)),
            ],
            options={
                "ordering": ["order", "name"],
            },
        ),
        migrations.CreateModel(
            name="Category",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=100)),
                ("slug", models.SlugField(unique=True)),
                ("description", models.TextField(blank=True)),
                ("order", models.IntegerField(default=0)),
                (
                    "parent",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="children",
                        to="services.category",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Categories",
                "ordering": ["order", "name"],
            },
        ),
        migrations.CreateModel(
            name="Service",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=200)),
                ("slug", models.SlugField(max_length=250, unique=True)),
                ("description", models.TextField()),
                (
                    "logo",
                    models.ImageField(
                        blank=True,
                        null=True,
                        upload_to="service_logos/",
                        validators=[hub.services.models.validate_image_size],
                    ),
                ),
                ("features", models.TextField()),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "categories",
                    models.ManyToManyField(
                        related_name="services", to="services.category"
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Lead",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=200)),
                ("company", models.CharField(max_length=200)),
                ("email", models.EmailField(max_length=254)),
                ("phone", models.CharField(max_length=50)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("odoo_lead_id", models.IntegerField(blank=True, null=True)),
                (
                    "plan",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="services.plan",
                    ),
                ),
                (
                    "service",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="services.service",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ExternalLink",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("url", models.URLField()),
                ("description", models.CharField(max_length=200)),
                ("order", models.IntegerField(default=0)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "service",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="external_links",
                        to="services.service",
                    ),
                ),
            ],
            options={
                "verbose_name": "External Link",
                "verbose_name_plural": "External Links",
                "ordering": ["order", "description"],
            },
        ),
        migrations.CreateModel(
            name="ConsultingPartner",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=200)),
                ("slug", models.SlugField(unique=True)),
                ("description", models.TextField()),
                (
                    "logo",
                    models.ImageField(
                        blank=True,
                        null=True,
                        upload_to="partner_logos/",
                        validators=[hub.services.models.validate_image_size],
                    ),
                ),
                ("website", models.URLField(blank=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "cloud_providers",
                    models.ManyToManyField(
                        blank=True,
                        related_name="consulting_partners",
                        to="services.cloudprovider",
                    ),
                ),
                (
                    "services",
                    models.ManyToManyField(
                        related_name="consulting_partners", to="services.service"
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="ServiceOffering",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("slug", models.SlugField(max_length=250, unique=True)),
                (
                    "description",
                    models.TextField(
                        help_text="Provider-specific details and features"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "cloud_provider",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="offerings",
                        to="services.cloudprovider",
                    ),
                ),
                (
                    "service",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="offerings",
                        to="services.service",
                    ),
                ),
            ],
            options={
                "ordering": ["service__name", "cloud_provider__name"],
                "unique_together": {("service", "cloud_provider")},
            },
        ),
        migrations.AddField(
            model_name="plan",
            name="offering",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="plans",
                to="services.serviceoffering",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="plan",
            unique_together={("offering", "name")},
        ),
        migrations.CreateModel(
            name="PlanPrice",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("price", models.DecimalField(decimal_places=2, max_digits=10)),
                (
                    "currency",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="services.currency",
                    ),
                ),
                (
                    "plan",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="prices",
                        to="services.plan",
                    ),
                ),
                (
                    "term",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT, to="services.term"
                    ),
                ),
            ],
            options={
                "unique_together": {("plan", "currency", "term")},
            },
        ),
        migrations.RunPython(create_initial_currencies),
        migrations.RunPython(create_initial_terms),
        migrations.RunPython(create_initial_categories),
    ]
