# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-01-11 08:05


from django.db import migrations, models

TELESCOPE_MIGRATION_MAP = {
    0: "REFR ACHRO",
    1: "REFR SEMI-APO",
    2: "REFR APO",
    3: "REFR NON-ACHRO GALILEAN",
    4: "REFR NON-ACHRO KEPLERIAN",
    5: "REFR SUPERACHRO",
    6: "REFL DALL-KIRKHAM",
    7: "REFL NASMYTH",
    8: "REFL RITCHEY CHRETIEN",
    9: "REFL GREGORIAN",
    10: "REFL HERSCHELLIAN",
    11: "REFL NEWTONIAN",
    12: "CATA ARGUNOV-CASSEGRAIN",
    13: "CATA KLEVTSOV-CASSEGRAIN",
    14: "CATA LURIE-HOUGHTON",
    15: "CATA MAKSUTOV",
    16: "CATA MAKSUTOV-CASSEGRAIN",
    17: "CATA MOD DALL-KIRKHAM",
    18: "CATA SCHMIDT CAMERA",
    19: "CATA SCHMIDT-CASSEGRAIN",
    20: "CATA ACF SCHMIDT-CASSEGRAIN",
    21: "CAMERA LENS",
    22: "BINOCULARS",
}  # type: Dict[int, str]


def getTelescopes(apps):
    return apps.get_model('astrobin', 'Telescope').objects.all()


def migrateTelescopeValues(apps, schema_editor):
    for i in getTelescopes(apps):
        if i.type:
            i.type = TELESCOPE_MIGRATION_MAP[int(i.type)]
            i.save()


def reverseMigrateTelescopeValues(apps, schema_editor):
    for telescope in getTelescopes(apps):
        if telescope.type:
            telescope.type = {v: k for k, v in TELESCOPE_MIGRATION_MAP.items()}[telescope.type]
            telescope.save()


CAMERA_MIGRATION_MAP = {
    0: "CCD",
    1: "DSLR",
    2: "GUIDER/PLANETARY",
    3: "FILM",
    4: "COMPACT",
    5: "VIDEO",
}  # type: Dict[int, str]


def getCameras(apps):
    return apps.get_model('astrobin', 'Camera').objects.all()


def migrateCameraValues(apps, schema_editor):
    for i in getCameras(apps):
        if i.type:
            i.type = CAMERA_MIGRATION_MAP[int(i.type)]
            i.save()


def reverseMigrateCameraValues(apps, schema_editor):
    for i in getCameras(apps):
        if i.type:
            i.type = {v: k for k, v in CAMERA_MIGRATION_MAP.items()}[i.type]
            i.save()


SOFTWARE_MIGRATION_MAP = {
    0: "OPEN_SOURCE_OR_FREEWARE",
    1: "PAID",
}  # type: Dict[int, str]


def getSoftware(apps):
    return apps.get_model('astrobin', 'Software').objects.all()


def migrateSoftwareValues(apps, schema_editor):
    for i in getSoftware(apps):
        if i.type:
            i.type = SOFTWARE_MIGRATION_MAP[int(i.type)]
            i.save()


def reverseMigrateSoftwareValues(apps, schema_editor):
    for i in getSoftware(apps):
        if i.type:
            i.type = {v: k for k, v in SOFTWARE_MIGRATION_MAP.items()}[i.type]
            i.save()


FILTER_MIGRATION_MAP = {
    0: "CLEAR_OR_COLOR",
    1: "BROAD HA",
    2: "BROAD HB",
    3: "BROAD SII",
    4: "BROAD OIII",
    5: "BROAD NII",
    6: "NARROW HA",
    7: "NARROW HB",
    8: "NARROW SII",
    9: "NARROW OIII",
    10: "NARROW NII",
    11: "LP",
    12: "PLANETARY",
    13: "OTHER",
    14: "UHC",
}  # type: Dict[int, str]


def getFilters(apps):
    return apps.get_model('astrobin', 'Filter').objects.all()


def migrateFilterValues(apps, schema_editor):
    for i in getFilters(apps):
        if i.type:
            i.type = FILTER_MIGRATION_MAP[int(i.type)]
            i.save()


def reverseMigrateFilterValues(apps, schema_editor):
    for i in getFilters(apps):
        if i.type:
            i.type = {v: k for k, v in FILTER_MIGRATION_MAP.items()}[i.type]
            i.save()


class Migration(migrations.Migration):
    dependencies = [
        ('astrobin', '0035_add_pixelskies_remote_source'),
    ]

    operations = [
        migrations.AlterField(
            model_name='telescope',
            name='type',
            field=models.CharField(
                blank=True,
                choices=[
                    ('REFR ACHRO', 'Refractor: achromatic'),
                    ('REFR SEMI-APO', 'Refractor: semi-apochromatic'),
                    ('REFR APO', 'Refractor: apochromatic'),
                    ('REFR NON-ACHRO GALILEAN', 'Refractor: non-achromatic Galilean'),
                    ('REFR NON-ACHRO KEPLERIAN', 'Refractor: non-achromatic Keplerian'),
                    ('REFR SUPERACHRO', 'Refractor: superachromat'),
                    ('REFL DALL-KIRKHAM', 'Reflector: Dall-Kirkham'),
                    ('REFL NASMYTH', 'Reflector: Nasmyth'),
                    ('REFL RITCHEY CHRETIEN', 'Reflector: Ritchey Chretien'),
                    ('REFL GREGORIAN', 'Reflector: Gregorian'),
                    ('REFL HERSCHELLIAN', 'Reflector: Herschellian'),
                    ('REFL NEWTONIAN', 'Reflector: Newtonian'),
                    ('CATA ARGUNOV-CASSEGRAIN', 'Catadioptric: Argunov-Cassegrain'),
                    ('CATA KLEVTSOV-CASSEGRAIN', 'Catadioptric: Klevtsov-Cassegrain'),
                    ('CATA LURIE-HOUGHTON', 'Catadioptric: Lurie-Houghton'),
                    ('CATA MAKSUTOV', 'Catadioptric: Maksutov'),
                    ('CATA MAKSUTOV-CASSEGRAIN', 'Catadioptric: Maksutov-Cassegrain'),
                    ('CATA MOD DALL-KIRKHAM', 'Catadioptric: modified Dall-Kirkham'),
                    ('CATA SCHMIDT CAMERA', 'Catadioptric: Schmidt camera'),
                    ('CATA SCHMIDT-CASSEGRAIN', 'Catadioptric: Schmidt-Cassegrain'),
                    ('CATA ACF SCHMIDT-CASSEGRAIN', 'Catadioptric: ACF Schmidt-Cassegrain'),
                    ('CAMERA LENS', 'Camera lens'),
                    ('BINOCULARS', 'Binoculars')
                ],
                max_length=64,
                null=True,
                verbose_name='Type'
            ),
        ),

        migrations.AlterField(
            model_name='camera',
            name='type',
            field=models.CharField(
                blank=True,
                choices=[
                    ('CCD', 'CCD'),
                    ('DSLR', 'DSLR'),
                    ('GUIDER/PLANETARY', 'Guider/Planetary'),
                    ('FILM', 'Film'),
                    ('COMPACT', 'Compact'),
                    ('VIDEO', 'Video camera'),
                ],
                max_length=64,
                null=True,
                verbose_name='Type'),
        ),

        migrations.AlterField(
            model_name='software',
            name='type',
            field=models.CharField(
                blank=True,
                choices=[
                    ('OPEN_SOURCE_OR_FREEWARE', 'Open Source or freeware'),
                    ('PAID', 'Paid'),
                ],
                max_length=64,
                null=True,
                verbose_name='Type'),
        ),

        migrations.AlterField(
            model_name='filter',
            name='type',
            field=models.CharField(
                blank=True,
                choices=[
                    ('CLEAR_OR_COLOR', 'Clear or color'),
                    ('BROAD HA', 'Broadband: H-Alpha'),
                    ('BROAD HB', 'Broadband: H-Beta'),
                    ('BROAD SII', 'Broadband: S-II'),
                    ('BROAD OIII', 'Broadband: O-II'),
                    ('BROAD NII', 'Broadband: N-II'),
                    ('NARROW HA', 'Narrowband: H-Alpha'),
                    ('NARROW HB', 'Narrowband: H-Beta'),
                    ('NARROW SII', 'Narrowband: S-II'),
                    ('NARROW OIII', 'Narrowband: O-II'),
                    ('NARROW NII', 'Narrowband: N-II'),
                    ('LP', 'Light pollution suppression'),
                    ('PLANETARY', 'Planetary'),
                    ('UHC', 'UHC: Ultra High Contrast'),
                    ('OTHER', 'Other'),
                ],
                max_length=64,
                null=True,
                verbose_name='Type'),
        ),

        migrations.RunPython(migrateTelescopeValues, reverseMigrateTelescopeValues),
        migrations.RunPython(migrateCameraValues, reverseMigrateCameraValues),
        migrations.RunPython(migrateSoftwareValues, reverseMigrateSoftwareValues),
        migrations.RunPython(migrateFilterValues, reverseMigrateFilterValues),
    ]
