# Generated by Django 4.2.20 on 2025-05-04 21:51

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


def create_update_status(apps, schema_editor):
    CharacterUpdateStatus = apps.get_model("ledger", "CharacterUpdateStatus")
    CharacterAudit = apps.get_model("ledger", "CharacterAudit")

    CorporationUpdateStatus = apps.get_model("ledger", "CorporationUpdateStatus")
    CorporationAudit = apps.get_model("ledger", "CorporationAudit")

    for character in CharacterAudit.objects.all():
        sections = ["wallet_journal", "mining_ledger", "planets", "planets_details"]
        for section in sections:
            update_status = CharacterUpdateStatus.objects.get_or_create(
                character=character,
                section=section,
            )[0]
            update_status.is_success = None
            update_status.error_message = ""
            update_status.has_token_error = False
            update_status.last_run_at = None
            update_status.last_run_finished_at = None
            update_status.save()

    for corporation in CorporationAudit.objects.all():
        sections = ["wallet_journal"]
        for section in sections:
            update_status = CorporationUpdateStatus.objects.get_or_create(
                corporation=corporation,
                section=section,
            )[0]
            update_status.is_success = None
            update_status.error_message = ""
            update_status.has_token_error = False
            update_status.last_run_at = None
            update_status.last_run_finished_at = None
            update_status.save()


class Migration(migrations.Migration):

    dependencies = [
        ("ledger", "0010_fetch_planets_and_update_planetdetails"),
    ]

    operations = [
        migrations.RunPython(create_update_status),
    ]
