# Generated by Django 3.2.25 on 2024-04-10 08:57

from django.db import migrations

from m3_gar.enums import (
    VersionUpdateStatus,
)


def update_version_status(apps, schema_editor):
    """Обновление значений поля Version.status."""
    Version = apps.get_model('m3_gar', 'Version')

    Version.objects.filter(
        processed=True,
    ).exclude(
        delta_xml_url='',
        complete_xml_url='',
    ).update(
        status=VersionUpdateStatus.FINISHED,
    )

    Version.objects.filter(
        processed=True,
        delta_xml_url='',
        complete_xml_url='',
    ).update(
        status=VersionUpdateStatus.SKIPPED,
    )


def set_processed_by_status(apps, schema_editor):
    """Обновляет поле processed по статусу."""
    Version = apps.get_model('m3_gar', 'Version')

    Version.objects.filter(
        status__in=VersionUpdateStatus.get_processed_statuses(),
    ).update(processed=True)


class Migration(migrations.Migration):

    dependencies = [
        ('m3_gar', '0019_version_status'),
    ]

    operations = [
        migrations.RunPython(update_version_status, set_processed_by_status)
    ]
