# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2020-04-21 19:05
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('dataentry', '0140_auto_20200412_1839'),
    ]

    operations = [
        # Add new person fields
        migrations.AddField(
            model_name='person',
            name='appearance',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='arrested',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='case_filed_against',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='education',
            field=models.CharField(max_length=126, null=True, verbose_name='Occupation'),
        ),
        migrations.AddField(
            model_name='person',
            name='guardian_name',
            field=models.CharField(max_length=126, null=True, verbose_name='Guardian Name'),
        ),
        migrations.AddField(
            model_name='person',
            name='guardian_phone',
            field=models.CharField(max_length=126, null=True, verbose_name='Guardian Phone'),
        ),
        migrations.AddField(
            model_name='person',
            name='guardian_relationship',
            field=models.CharField(max_length=1024, null=True, verbose_name='Guardian Relationship'),
        ),
        migrations.AddField(
            model_name='person',
            name='interviewer_believes',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='occupation',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='photo',
            field=models.ImageField(blank=True, default='', upload_to='interceptee_photos'),
        ),
        migrations.AddField(
            model_name='person',
            name='anonymized_photo',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='pv_believes',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='role',
            field=models.CharField(max_length=126, null=True),
        ),
        migrations.AddField(
            model_name='person',
            name='social_media',
            field=models.CharField(max_length=1024, null=True),
        ),
        
        # Move data into new person fields
        migrations.RunSQL("update dataentry_person set (photo, anonymized_photo, arrested, role) = ("\
                          "select photo, anonymized_photo, case when trafficker_taken_into_custody = true then 'Yes' else 'No' end, "\
                          "case when kind='v' then 'PVOT' else 'Suspect' end "\
                          "from dataentry_intercepteecommon "\
                          "where dataentry_person.id = dataentry_intercepteecommon.person_id ) "
                        "where id in (select person_id from dataentry_intercepteecommon)"),
        migrations.RunSQL("update dataentry_person set (social_media, occupation, education, guardian_name, guardian_phone, guardian_relationship) = ("\
                          "select social_media, occupation, education, guardian_name, guardian_phone, guardian_relationship "\
                          "from dataentry_cifcommon "\
                          "where id = (select min(id) from dataentry_cifcommon where dataentry_person.id = dataentry_cifcommon.main_pv_id)) "\
                        "where id in (select main_pv_id from dataentry_cifcommon)"),
        migrations.RunSQL("update dataentry_person set (case_filed_against, arrested, social_media, role, appearance, occupation, interviewer_believes, pv_believes) = ("\
                          "select case when case_filed_against = 'True' then 'Yes' when case_filed_against = 'False' then 'No' else null end, "\
                          "case when arrested='True' then 'Yes' when arrested='False' then 'No' else null end, social_media, null, appearance, occupation, null,null "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_broker = true and role is null then 'Broker' "\
                            "when role_broker = 'true' and role is not null then dataentry_person.role || ';Broker' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_companion = true and role is null then 'Companion' "\
                            "when role_companion = 'true' and role is not null then dataentry_person.role || ';Companion' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_host = true and role is null then 'Host' "\
                            "when role_host = 'true' and role is not null then dataentry_person.role || ';Host' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_id_facilitator = true and role is null then 'ID Facilitator' "\
                            "when role_id_facilitator = 'true' and role is not null then dataentry_person.role || ';ID Facilitator' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_agent = true and role is null then 'Agent' "\
                            "when role_agent = 'true' and role is not null then dataentry_person.role || ';Agent' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_witness = true and role is null then 'Witness' "\
                            "when role_witness = 'true' and role is not null then dataentry_person.role || ';Witness' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_complainant = true and role is null then 'Complainant' "
                            "when role_complainant = 'true' and role is not null then dataentry_person.role || ';Complainant' "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set role = ("\
                          "select case "\
                            "when role_other != '' and role is null then role_other "\
                            "when role_other != '' and role is not null then dataentry_person.role || ';' || role_other "\
                            "else dataentry_person.role end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set interviewer_believes = ("
                          "select case "\
                            "when definitely_trafficked_many = true then 'Definitely trafficked many people' "\
                            "when has_trafficked_some = true then 'Has trafficked some people' "\
                            "when suspected_trafficker = true then 'Suspect s/he''s a trafficker' "\
                            "when dont_believe_trafficker = true then 'Don''t believe s/he''s a trafficker' "\
                            "else null end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set pv_believes = ("\
                          "select case "\
                            "when pv_definitely_trafficked_many = true then 'Definitely trafficked many people' "\
                            "when pv_has_trafficked_some = true then 'Has trafficked some people' "\
                            "when pv_suspected_trafficker = true then 'Suspect s/he''s a trafficker' "\
                            "when pv_dont_believe_trafficker = true then 'Don''t believe s/he''s a trafficker' "\
                            "else null end "\
                          "from dataentry_personboxcommon "\
                          "where id = (select min(id) from dataentry_personboxcommon where dataentry_person.id = dataentry_personboxcommon.person_id)) "\
                        "where id in (select person_id from dataentry_personboxcommon)"),
        migrations.RunSQL("update dataentry_person set (occupation, guardian_name, guardian_phone) = ("\
                          "select occupation, guardian_name, guardian_phone "\
                          "from dataentry_vdfcommon "\
                          "where dataentry_person.id = dataentry_vdfcommon.victim_id ) "\
                        "where id in (select victim_id from dataentry_vdfcommon)"),
    ]
