from django.db import migrations


def update_auth_invalid_credentials_message(apps, schema_editor):
    APIMessage = apps.get_model('core', 'APIMessage')
    Language = apps.get_model('core', 'Language')

    try:
        language = Language.objects.get(code='fi')
        APIMessage.objects.filter(
            message_key='AUTH_INVALID_CREDENTIALS',
            language=language
        ).update(
            message='Virheellinen käyttäjätunnus tai salasana.'
        )
    except Language.DoesNotExist:
        pass


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0018_update_message_device_set'),
    ]

    operations = [
        migrations.RunPython(update_auth_invalid_credentials_message),
    ]
