# Generated by Django 4.2.24 on 2025-09-23 07:48

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

# AA SRP
import aasrp.models


def on_default_settings_migrate(apps, schema_editor):
    """
    Create default settings on migration

    :param apps:
    :param schema_editor:
    :return:
    """

    Setting = apps.get_model("aasrp", "Setting")
    db_alias = schema_editor.connection.alias

    Setting.objects.using(db_alias).create(pk=1)


def on_default_settings_migrate_zero(apps, schema_editor):
    """
    Remove default settings on migration to zero

    :param apps:
    :param schema_editor:
    :return:
    """

    Setting = apps.get_model("aasrp", "Setting")
    db_alias = schema_editor.connection.alias
    Setting.objects.using(db_alias).delete()


class Migration(migrations.Migration):

    replaces = [
        ("aasrp", "0001_initial"),
        ("aasrp", "0002_relations_update"),
        ("aasrp", "0003_aasrprequest_reject_info"),
        ("aasrp", "0004_aasrpusersettings"),
        ("aasrp", "0005_insurance"),
        ("aasrp", "0006_related_names"),
        ("aasrp", "0007_aasrprequestcomment_comment_time_and_more"),
        ("aasrp", "0008_aasrprequestcomment_new_status_and_more"),
        ("aasrp", "0009_add_fleet_type_to_srp_link"),
        ("aasrp", "0010_model_changes"),
        ("aasrp", "0011_default_settings"),
        ("aasrp", "0012_alter_fleettype_options_alter_insurance_options_and_more"),
        ("aasrp", "0013_setting_loss_value_source"),
        ("aasrp", "0014_alter_srprequest_ship"),
    ]

    initial = True

    dependencies = [
        ("eveonline", "0017_alliance_and_corp_names_are_not_unique"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="AaSrp",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
            ],
            options={
                "verbose_name": "AA-SRP",
                "permissions": (
                    ("basic_access", "Can access the AA-SRP module"),
                    ("create_srp", "Can create new SRP links"),
                    ("manage_srp", "Can manage SRP"),
                    ("manage_srp_requests", "Can manage SRP requests"),
                ),
                "managed": False,
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="FleetType",
            fields=[
                ("id", models.AutoField(primary_key=True, serialize=False)),
                (
                    "name",
                    models.CharField(
                        help_text="Descriptive name of your fleet type",
                        max_length=254,
                        verbose_name="Name",
                    ),
                ),
                (
                    "is_enabled",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this fleet type is active or not",
                        verbose_name="Is enabled",
                    ),
                ),
            ],
            options={
                "verbose_name": "Fleet type",
                "verbose_name_plural": "Fleet types",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="Setting",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "srp_team_discord_channel_id",
                    models.PositiveBigIntegerField(
                        blank=True,
                        default=None,
                        null=True,
                        verbose_name="SRP team Discord channel ID",
                    ),
                ),
                (
                    "loss_value_source",
                    models.CharField(
                        choices=[
                            ("fittedValue", "Fitted value (Ship and Fitting)"),
                            ("totalValue", "Total value (Ship, Fitting and Cargo)"),
                        ],
                        default="totalValue",
                        help_text="The source for the loss value of a killmail. Fitted value is the value of the ship and its fitting. Total value is the value of the ship, its fitting and the cargo. (Default: Total value)",
                        max_length=11,
                        verbose_name="Loss value source",
                    ),
                ),
            ],
            options={
                "verbose_name": "Setting",
                "verbose_name_plural": "Settings",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="SrpLink",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "srp_name",
                    models.CharField(
                        default="", max_length=254, verbose_name="SRP name"
                    ),
                ),
                (
                    "srp_status",
                    models.CharField(
                        choices=[
                            ("Active", "Active"),
                            ("Closed", "Closed"),
                            ("Completed", "Completed"),
                        ],
                        default="Active",
                        max_length=9,
                        verbose_name="SRP status",
                    ),
                ),
                (
                    "srp_code",
                    models.CharField(
                        default="", max_length=16, verbose_name="SRP code"
                    ),
                ),
                (
                    "fleet_doctrine",
                    models.CharField(
                        default="", max_length=254, verbose_name="Doctrine"
                    ),
                ),
                ("fleet_time", models.DateTimeField(verbose_name="Fleet time")),
                (
                    "aar_link",
                    models.CharField(
                        blank=True, default="", max_length=254, verbose_name="AAR link"
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        help_text="Who created the SRP link?",
                        null=True,
                        on_delete=models.SET(aasrp.models.get_sentinel_user),
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Creator",
                    ),
                ),
                (
                    "fleet_commander",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="eveonline.evecharacter",
                        verbose_name="Fleet commander",
                    ),
                ),
                (
                    "fleet_type",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        help_text="The SRP link fleet type, if it's set",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="aasrp.fleettype",
                        verbose_name="Fleet type",
                    ),
                ),
            ],
            options={
                "verbose_name": "SRP link",
                "verbose_name_plural": "SRP links",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="UserSetting",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "disable_notifications",
                    models.BooleanField(
                        default=False, verbose_name="Disable notifications"
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=models.SET(aasrp.models.get_sentinel_user),
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="User",
                    ),
                ),
            ],
            options={
                "verbose_name": "User settings",
                "verbose_name_plural": "User settings",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="SrpRequest",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "request_code",
                    models.CharField(
                        default="", max_length=254, verbose_name="Request code"
                    ),
                ),
                (
                    "ship_name",
                    models.CharField(
                        default="", max_length=254, verbose_name="Ship type"
                    ),
                ),
                (
                    "ship_id",
                    models.PositiveBigIntegerField(
                        blank=True, default=None, null=True, verbose_name="Ship type ID"
                    ),
                ),
                (
                    "killboard_link",
                    models.CharField(
                        default="", max_length=254, verbose_name="Killboard link"
                    ),
                ),
                (
                    "additional_info",
                    models.TextField(
                        blank=True, default="", verbose_name="Additional information"
                    ),
                ),
                (
                    "request_status",
                    models.CharField(
                        choices=[
                            ("Pending", "Pending"),
                            ("Approved", "Approved"),
                            ("Rejected", "Rejected"),
                        ],
                        default="Pending",
                        max_length=8,
                        verbose_name="Request status",
                    ),
                ),
                (
                    "payout_amount",
                    models.BigIntegerField(default=0, verbose_name="Payout amount"),
                ),
                (
                    "loss_amount",
                    models.BigIntegerField(default=0, verbose_name="Loss amount"),
                ),
                (
                    "post_time",
                    models.DateTimeField(
                        default=django.utils.timezone.now, verbose_name="Request time"
                    ),
                ),
                (
                    "reject_info",
                    models.TextField(
                        blank=True, default="", verbose_name="Reject reason"
                    ),
                ),
                (
                    "character",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="eveonline.evecharacter",
                        verbose_name="Character",
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        help_text="Who created the SRP request?",
                        null=True,
                        on_delete=models.SET(aasrp.models.get_sentinel_user),
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Creator",
                    ),
                ),
                (
                    "srp_link",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="srp_requests",
                        to="aasrp.srplink",
                        verbose_name="SRP link",
                    ),
                ),
            ],
            options={
                "verbose_name": "Request",
                "verbose_name_plural": "Requests",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="RequestComment",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "comment",
                    models.TextField(blank=True, default="", verbose_name="Comment"),
                ),
                (
                    "comment_type",
                    models.CharField(
                        choices=[
                            ("Comment", "Comment"),
                            ("Request Added", "SRP request added"),
                            ("Request Information", "Additional information"),
                            ("Reject Reason", "Reject reason"),
                            ("Status Changed", "Status changed"),
                            ("Reviser Comment", "Reviser comment"),
                        ],
                        default="Comment",
                        max_length=19,
                        verbose_name="Comment type",
                    ),
                ),
                (
                    "comment_time",
                    models.DateTimeField(
                        blank=True,
                        default=django.utils.timezone.now,
                        null=True,
                        verbose_name="Comment time",
                    ),
                ),
                (
                    "new_status",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("Pending", "Pending"),
                            ("Approved", "Approved"),
                            ("Rejected", "Rejected"),
                        ],
                        default="",
                        max_length=8,
                        verbose_name="New SRP request status",
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=models.SET(aasrp.models.get_sentinel_user),
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Creator",
                    ),
                ),
                (
                    "srp_request",
                    models.ForeignKey(
                        blank=True,
                        default=None,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="srp_request_comments",
                        to="aasrp.srprequest",
                        verbose_name="SRP request",
                    ),
                ),
            ],
            options={
                "verbose_name": "Comment",
                "verbose_name_plural": "Comments",
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="Insurance",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "insurance_level",
                    models.CharField(
                        default="", max_length=254, verbose_name="Insurance level"
                    ),
                ),
                ("insurance_cost", models.FloatField(verbose_name="Insurance cost")),
                (
                    "insurance_payout",
                    models.FloatField(verbose_name="Insurance payout"),
                ),
                (
                    "srp_request",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="insurance",
                        to="aasrp.srprequest",
                        verbose_name="SRP request",
                    ),
                ),
            ],
            options={
                "verbose_name": "Ship insurance",
                "verbose_name_plural": "Ship insurances",
                "default_permissions": (),
            },
        ),
        migrations.RunPython(
            code=on_default_settings_migrate,
            reverse_code=on_default_settings_migrate_zero,
        ),
    ]
