# Generated by Django 5.1.7 on 2025-03-13 16:59

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


# Functions from the following migrations need manual copying.
# Move them and any dependencies into this file, then update the
# RunPython operations to refer to the local versions:
# apps.stripe.migrations.0009_remove_stripesubscription_product_and_more


class Migration(migrations.Migration):
    replaces = [
        ("stripe", "0001_squashed_0006_stripeproduct_name"),
        ("stripe", "0007_remove_stripeproduct_price_alter_stripeproduct_name_and_more"),
        (
            "stripe",
            "0008_remove_stripesubscription_unique_primary_subscription_per_organization_and_more",
        ),
        ("stripe", "0009_remove_stripesubscription_product_and_more"),
        ("stripe", "0010_remove_stripesubscription_product_and_more"),
        ("stripe", "0011_remove_stripesubscription_is_active_and_more"),
    ]

    initial = True

    dependencies = [
        ("organizations_ext", "0006_organization_stripe_subscription_id"),
        (
            "organizations_ext",
            "0007_rename_stripe_subscription_id_organization_stripe_customer_id",
        ),
    ]

    operations = [
        migrations.CreateModel(
            name="StripeProduct",
            fields=[
                (
                    "stripe_id",
                    models.CharField(max_length=30, primary_key=True, serialize=False),
                ),
                ("description", models.TextField()),
                ("events", models.PositiveBigIntegerField()),
                ("is_public", models.BooleanField()),
                ("name", models.CharField()),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="StripePrice",
            fields=[
                (
                    "stripe_id",
                    models.CharField(max_length=30, primary_key=True, serialize=False),
                ),
                ("price", models.DecimalField(decimal_places=2, max_digits=10)),
                ("nickname", models.CharField(max_length=255)),
                (
                    "product",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="stripe.stripeproduct",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="stripeproduct",
            name="default_price",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="stripe.stripeprice",
            ),
        ),
        migrations.CreateModel(
            name="StripeSubscription",
            fields=[
                (
                    "stripe_id",
                    models.CharField(max_length=30, primary_key=True, serialize=False),
                ),
                ("current_period_start", models.DateTimeField()),
                ("current_period_end", models.DateTimeField()),
                (
                    "organization",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="organizations_ext.organization",
                    ),
                ),
                (
                    "product",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="stripe.stripeproduct",
                    ),
                ),
                ("is_active", models.BooleanField()),
                ("created", models.DateTimeField()),
            ],
            options={
                "abstract": False,
                "constraints": [],
            },
        ),
        migrations.RemoveField(
            model_name="stripesubscription",
            name="product",
        ),
        migrations.AddField(
            model_name="stripesubscription",
            name="price",
            field=models.ForeignKey(
                default="",
                on_delete=django.db.models.deletion.RESTRICT,
                to="stripe.stripeprice",
            ),
            preserve_default=False,
        ),
        migrations.RemoveField(
            model_name="stripesubscription",
            name="is_active",
        ),
        migrations.AddField(
            model_name="stripesubscription",
            name="collection_method",
            field=models.CharField(
                choices=[
                    ("charge_automatically", "Charge Automatically"),
                    ("send_invoice", "Send Invoice"),
                ],
                default="charge_automatically",
                max_length=20,
            ),
        ),
        migrations.AddField(
            model_name="stripesubscription",
            name="start_date",
            field=models.DateTimeField(default=django.utils.timezone.now),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="stripesubscription",
            name="status",
            field=models.CharField(
                choices=[
                    ("incomplete", "Incomplete"),
                    ("incomplete_expired", "Incomplete Expired"),
                    ("trialing", "Trialing"),
                    ("active", "Active"),
                    ("past_due", "Past Due"),
                    ("canceled", "Canceled"),
                    ("unpaid", "Unpaid"),
                    ("paused", "Paused"),
                ],
                db_index=True,
                max_length=18,
                default="canceled",
            ),
        ),
    ]
