# Generated by Django 2.0.5 on 2018-05-21 05:11

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("user_payments", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Subscription",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        help_text="Codes must be unique per user. Allows identifying the subscription.",
                        max_length=20,
                        verbose_name="code",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now, verbose_name="created at"
                    ),
                ),
                ("title", models.CharField(max_length=200, verbose_name="title")),
                ("starts_on", models.DateField(verbose_name="starts on")),
                (
                    "ends_on",
                    models.DateField(blank=True, null=True, verbose_name="ends on"),
                ),
                (
                    "periodicity",
                    models.CharField(
                        choices=[
                            ("yearly", "yearly"),
                            ("quarterly", "quarterly"),
                            ("monthly", "monthly"),
                            ("weekly", "weekly"),
                            ("manually", "manually"),
                        ],
                        max_length=20,
                        verbose_name="periodicity",
                    ),
                ),
                (
                    "amount",
                    models.DecimalField(
                        decimal_places=2, max_digits=10, verbose_name="amount"
                    ),
                ),
                (
                    "renew_automatically",
                    models.BooleanField(
                        default=True, verbose_name="renew automatically"
                    ),
                ),
                ("paid_until", models.DateField(blank=True, verbose_name="paid until")),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="user_subscriptions",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="user",
                    ),
                ),
            ],
            options={
                "verbose_name": "subscription",
                "verbose_name_plural": "subscriptions",
            },
        ),
        migrations.CreateModel(
            name="SubscriptionPeriod",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("starts_on", models.DateField(verbose_name="starts on")),
                ("ends_on", models.DateField(verbose_name="ends on")),
                (
                    "line_item",
                    models.OneToOneField(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        to="user_payments.LineItem",
                        verbose_name="line item",
                    ),
                ),
                (
                    "subscription",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="periods",
                        to="user_subscriptions.Subscription",
                        verbose_name="subscription",
                    ),
                ),
            ],
            options={
                "verbose_name": "subscription period",
                "verbose_name_plural": "subscription periods",
            },
        ),
        migrations.AlterUniqueTogether(
            name="subscriptionperiod", unique_together={("subscription", "starts_on")}
        ),
        migrations.AlterUniqueTogether(
            name="subscription", unique_together={("user", "code")}
        ),
    ]
