"""Initial migration for PI FYAD."""

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("eveonline", "0001_initial"),
    ]

    operations = [
        # Permissions proxy model
        migrations.CreateModel(
            name="PiFyadGeneral",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
            ],
            options={
                "managed": False,
                "default_permissions": (),
                "permissions": [
                    ("view_pi", "Can view own PI data"),
                    ("view_corp_pi", "Can view corporation PI data"),
                    ("view_alliance_pi", "Can view alliance PI data"),
                    ("manage_templates", "Can create and manage PI templates"),
                ],
            },
        ),
        # CharacterOwner
        migrations.CreateModel(
            name="CharacterOwner",
            fields=[
                ("character", models.OneToOneField(
                    on_delete=django.db.models.deletion.CASCADE,
                    primary_key=True,
                    related_name="pi_fyad_owner",
                    serialize=False,
                    to="eveonline.evecharacter",
                )),
                ("last_planet_sync", models.DateTimeField(blank=True, null=True)),
                ("last_customs_sync", models.DateTimeField(blank=True, null=True)),
                ("sync_enabled", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={"default_permissions": ()},
        ),
        # CharacterPlanet
        migrations.CreateModel(
            name="CharacterPlanet",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("planet_id", models.IntegerField()),
                ("planet_type_id", models.IntegerField()),
                ("planet_name", models.CharField(blank=True, default="", max_length=255)),
                ("solar_system_id", models.IntegerField()),
                ("solar_system_name", models.CharField(blank=True, default="", max_length=255)),
                ("upgrade_level", models.IntegerField(default=0)),
                ("num_pins", models.IntegerField(default=0)),
                ("last_update", models.DateTimeField(blank=True, null=True)),
                ("owner", models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="planets",
                    to="pi_fyad.characterowner",
                )),
            ],
            options={
                "default_permissions": (),
                "unique_together": {("owner", "planet_id")},
                "ordering": ["solar_system_name", "planet_name"],
            },
        ),
        # PlanetPin
        migrations.CreateModel(
            name="PlanetPin",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("pin_id", models.BigIntegerField()),
                ("type_id", models.IntegerField()),
                ("type_name", models.CharField(blank=True, default="", max_length=255)),
                ("group_id", models.IntegerField(default=0)),
                ("schematic_id", models.IntegerField(blank=True, null=True)),
                ("latitude", models.FloatField(default=0.0)),
                ("longitude", models.FloatField(default=0.0)),
                ("is_extractor", models.BooleanField(default=False)),
                ("extractor_product_type_id", models.IntegerField(blank=True, null=True)),
                ("extractor_product_name", models.CharField(blank=True, default="", max_length=255)),
                ("extractor_cycle_time", models.IntegerField(blank=True, null=True)),
                ("extractor_head_count", models.IntegerField(default=0)),
                ("extractor_qty_per_cycle", models.IntegerField(default=0)),
                ("install_time", models.DateTimeField(blank=True, null=True)),
                ("expiry_time", models.DateTimeField(blank=True, null=True)),
                ("is_storage", models.BooleanField(default=False)),
                ("storage_capacity_m3", models.FloatField(default=0.0)),
                ("storage_used_m3", models.FloatField(default=0.0)),
                ("storage_fill_pct", models.FloatField(default=0.0)),
                ("is_factory", models.BooleanField(default=False)),
                ("factory_tier", models.IntegerField(default=0)),
                ("factory_output_type_id", models.IntegerField(blank=True, null=True)),
                ("factory_output_name", models.CharField(blank=True, default="", max_length=255)),
                ("last_update", models.DateTimeField(blank=True, null=True)),
                ("planet", models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="pins",
                    to="pi_fyad.characterplanet",
                )),
            ],
            options={
                "default_permissions": (),
                "unique_together": {("planet", "pin_id")},
                "ordering": ["-is_extractor", "-is_factory", "-is_storage"],
            },
        ),
        # StorageContents
        migrations.CreateModel(
            name="StorageContents",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("type_id", models.IntegerField()),
                ("type_name", models.CharField(blank=True, default="", max_length=255)),
                ("quantity", models.BigIntegerField(default=0)),
                ("volume_per_unit", models.FloatField(default=0.0)),
                ("total_volume", models.FloatField(default=0.0)),
                ("pin", models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="contents",
                    to="pi_fyad.planetpin",
                )),
            ],
            options={
                "default_permissions": (),
                "unique_together": {("pin", "type_id")},
                "ordering": ["-total_volume"],
            },
        ),
        # CustomsOffice
        migrations.CreateModel(
            name="CustomsOffice",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("office_id", models.BigIntegerField()),
                ("owner_id", models.IntegerField(blank=True, null=True)),
                ("tax_rate", models.FloatField(default=0.0)),
                ("reinforcement_exit_start", models.IntegerField(default=0)),
                ("reinforcement_exit_end", models.IntegerField(default=0)),
                ("allow_alliance", models.BooleanField(default=False)),
                ("allow_standings", models.BooleanField(default=False)),
                ("last_update", models.DateTimeField(blank=True, null=True)),
                ("planet", models.OneToOneField(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="customs_office",
                    to="pi_fyad.characterplanet",
                )),
            ],
            options={"default_permissions": ()},
        ),
        # PlanetTemplate
        migrations.CreateModel(
            name="PlanetTemplate",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("name", models.CharField(max_length=255)),
                ("description", models.TextField(blank=True, default="")),
                ("planet_type_id", models.IntegerField()),
                ("planet_type_name", models.CharField(blank=True, default="", max_length=100)),
                ("corporation_id", models.IntegerField(blank=True, null=True)),
                ("alliance_id", models.IntegerField(blank=True, null=True)),
                ("visibility", models.CharField(
                    choices=[
                        ("private", "Private"),
                        ("corp", "Corporation"),
                        ("alliance", "Alliance"),
                        ("public", "Public"),
                    ],
                    default="private",
                    max_length=20,
                )),
                ("template_data", models.JSONField(default=dict)),
                ("clipboard_raw", models.TextField(blank=True, default="")),
                ("pin_count", models.IntegerField(default=0)),
                ("factory_count", models.IntegerField(default=0)),
                ("extractor_count", models.IntegerField(default=0)),
                ("output_products", models.JSONField(default=list)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("created_by", models.ForeignKey(
                    blank=True,
                    null=True,
                    on_delete=django.db.models.deletion.SET_NULL,
                    related_name="pi_templates_created",
                    to="eveonline.evecharacter",
                )),
            ],
            options={
                "default_permissions": (),
                "ordering": ["-updated_at"],
            },
        ),
        # TemplatePin
        migrations.CreateModel(
            name="TemplatePin",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("pin_index", models.IntegerField()),
                ("type_id", models.IntegerField()),
                ("type_name", models.CharField(blank=True, default="", max_length=255)),
                ("group_id", models.IntegerField(default=0)),
                ("latitude", models.FloatField(default=0.0)),
                ("longitude", models.FloatField(default=0.0)),
                ("schematic_id", models.IntegerField(blank=True, null=True)),
                ("is_extractor", models.BooleanField(default=False)),
                ("is_factory", models.BooleanField(default=False)),
                ("is_storage", models.BooleanField(default=False)),
                ("factory_tier", models.IntegerField(default=0)),
                ("factory_output_type_id", models.IntegerField(blank=True, null=True)),
                ("factory_output_name", models.CharField(blank=True, default="", max_length=255)),
                ("template", models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="template_pins",
                    to="pi_fyad.planettemplate",
                )),
            ],
            options={
                "default_permissions": (),
                "ordering": ["pin_index"],
                "unique_together": {("template", "pin_index")},
            },
        ),
    ]
