# Generated by Django 2.2.13 on 2021-03-01 16:49

import django.db.models.deletion
import mptt.fields
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("NEMO", "0027_version_3_8_0"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    def create_rate_types(apps, schema_editor):
        RateTypeModel = apps.get_model("rates", "RateType")
        if not RateTypeModel.objects.exists():
            RateTypeModel.objects.create(type="TOOL_USAGE", category_specific=True, item_specific=True)
            RateTypeModel.objects.create(type="TOOL_TRAINING_INDIVIDUAL", category_specific=True, item_specific=True)
            RateTypeModel.objects.create(type="TOOL_TRAINING_GROUP", category_specific=True, item_specific=True)
            RateTypeModel.objects.create(type="TOOL_MISSED_RESERVATION", category_specific=False, item_specific=False)
            RateTypeModel.objects.create(type="AREA_USAGE", category_specific=True, item_specific=True)
            RateTypeModel.objects.create(type="AREA_MISSED_RESERVATION", category_specific=False, item_specific=False)
            RateTypeModel.objects.create(type="CONSUMABLE", category_specific=False, item_specific=True)
            RateTypeModel.objects.create(type="STAFF_CHARGE", category_specific=True, item_specific=False)

    operations = [
        migrations.CreateModel(
            name="RateCategory",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("name", models.CharField(help_text="The name of this rate category", max_length=200)),
            ],
            options={
                "verbose_name": "Rate category",
                "verbose_name_plural": "Rate categories",
            },
        ),
        migrations.CreateModel(
            name="RateType",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "type",
                    models.CharField(
                        choices=[
                            (
                                "Tool",
                                (
                                    ("TOOL_USAGE", "Tool usage"),
                                    ("TOOL_TRAINING_INDIVIDUAL", "Tool individual training"),
                                    ("TOOL_TRAINING_GROUP", "Tool group training"),
                                    ("TOOL_MISSED_RESERVATION", "Tool missed reservation"),
                                ),
                            ),
                            (
                                "Area",
                                (("AREA_USAGE", "Area usage"), ("AREA_MISSED_RESERVATION", "Area missed reservation")),
                            ),
                            ("CONSUMABLE", "Consumable/Supply"),
                            ("STAFF_CHARGE", "Staff charge"),
                        ],
                        max_length=100,
                    ),
                ),
                (
                    "category_specific",
                    models.BooleanField(
                        default=False,
                        help_text="Check this box to make this rate type category specific (i.e. you will need to enter a rate for each category)",
                    ),
                ),
                (
                    "item_specific",
                    models.BooleanField(
                        default=False,
                        help_text="Check this box to make this rate type item specific (i.e. you will need to enter a rate for each item)",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="RateLog",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("object_id", models.PositiveIntegerField(null=True)),
                ("action", models.IntegerField(choices=[(0, "Add"), (1, "Delete"), (2, "Update")])),
                ("date", models.DateTimeField(auto_now_add=True)),
                ("details", models.TextField(blank=True, null=True)),
                (
                    "content_type",
                    models.ForeignKey(
                        null=True, on_delete=django.db.models.deletion.SET_NULL, to="contenttypes.ContentType"
                    ),
                ),
                ("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name="Rate",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "amount",
                    models.DecimalField(
                        decimal_places=2, max_digits=8, help_text="The rate per hour if this isn't a flat rate"
                    ),
                ),
                (
                    "flat",
                    models.BooleanField(
                        default=False, help_text="Check this box to make this a flat rate (independent of time)"
                    ),
                ),
                (
                    "minimum_charge",
                    models.DecimalField(
                        decimal_places=2,
                        max_digits=8,
                        blank=True,
                        help_text="The minimum charge for this rate",
                        null=True,
                    ),
                ),
                (
                    "area",
                    mptt.fields.TreeForeignKey(
                        blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="NEMO.Area"
                    ),
                ),
                (
                    "category",
                    models.ForeignKey(
                        blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="rates.RateCategory"
                    ),
                ),
                (
                    "consumable",
                    models.ForeignKey(
                        blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="NEMO.Consumable"
                    ),
                ),
                (
                    "tool",
                    models.ForeignKey(
                        blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="NEMO.Tool"
                    ),
                ),
                ("type", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="rates.RateType")),
            ],
        ),
        migrations.RunPython(create_rate_types),
    ]
