# Generated by Django 3.2.13 on 2024-10-25 12:51

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('ddm', '0052_auto_20241025_1451'),
    ]

    operations = [
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.CreateModel(
                    name='DonationBlueprint',
                    fields=[
                        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                        ('name', models.CharField(help_text='Name for this File Blueprint. Will be visible to participants, so pick an informative name (e.g., "Watch History").', max_length=250)),
                        ('description', models.TextField(help_text='A description of which kind of data will be extracted by this Blueprint (e.g., "The title of your watched videos will be collected together with the time when you watched it."). Will be visible to participants.', null=True)),
                        ('exp_file_format', models.CharField(choices=[('json', 'JSON file'), ('csv', 'CSV file')], default='json', max_length=10, verbose_name='Expected file format')),
                        ('json_extraction_root', models.CharField(blank=True, default='', help_text="Indicates on which level of the files' data structure information should be extractet. If you want to extract information contained on the first level (e.g., {'field to be extracted': value}, you can leave this field empty. If you want to extract data located on a higher level, then you would provide the path to the parent field of the data you want to extract (e.g., if your json file is structured like this {'friends': {'real_friends': [{'name to extract': name, 'date to extract': date}], 'fake friends': [{'name': name, 'date': date }]}} and you want to extract the names and dates of real_friends, you would set the extraction root to 'friends.real_friends'.", max_length=200, verbose_name='Extraction Root')),
                        ('csv_delimiter', models.CharField(blank=True, default='', max_length=10)),
                        ('expected_fields', models.TextField(help_text='Put the field names in double quotes (") and separate them with commas ("Field A", "Field B").', validators=[django.core.validators.RegexValidator('^((["][^"]+["]))(\\s*,\\s*((["][^"]+["])))*[,\\s]*$', message='Field must contain one or multiple comma separated strings. Strings must be enclosed in double quotes ("string").')])),
                        ('expected_fields_regex_matching', models.BooleanField(default=False, help_text='Select if you use regex expressions in the "Excpected fields".')),
                        ('regex_path', models.TextField(blank=True, help_text='The path where the file is expected to be located in the uploaded ZIP folder. You can use Regex to, e.g., add wildcard characters or to match files in different languages. Consult the documentation for some examples.', null=True, verbose_name='File path')),
                    ],
                ),
                migrations.CreateModel(
                    name='ProcessingRule',
                    fields=[
                        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                        ('name', models.CharField(help_text='An informative name for this rule. Only used internally.', max_length=250)),
                        ('field', models.TextField(help_text='The field on which the rule will be applied (just as a string without quotes).If a field is mentioned in a rule, it will be kept in the data that are sent to the server.')),
                        ('regex_field', models.BooleanField(default=False, help_text='Select if you use a regex expression in the "Field" setting to match a variable.')),
                        ('execution_order', models.IntegerField(help_text='The order in which the extraction steps are executed.')),
                        ('comparison_operator', models.CharField(blank=True, choices=[('', 'Keep Field'), ('==', 'Equal (==)'), ('!=', 'Not Equal (!=)'), ('>', 'Greater than (>)'), ('<', 'Smaller than (<)'), ('>=', 'Greater than or equal (>=)'), ('<=', 'Smaller than or equal (<=)'), ('regex-delete-match', 'Delete match (regex)'), ('regex-replace-match', 'Replace match (regex)'), ('regex-delete-row', 'Delete row when match (regex)')], default=None, max_length=24, null=True, verbose_name='Extraction Operator')),
                        ('comparison_value', models.TextField(blank=True, help_text='The value against which the data contained in the indicated field will be compared according to the selected comparison logic.')),
                        ('replacement_value', models.TextField(blank=True, help_text='Only required for operation "Replace match (regex)".')),
                        ('blueprint', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ddm_datadonation.donationblueprint')),
                    ],
                ),
                migrations.CreateModel(
                    name='FileUploader',
                    fields=[
                        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                        ('name', models.CharField(max_length=250)),
                        ('index', models.PositiveIntegerField()),
                        ('upload_type', models.CharField(choices=[('zip file', 'Zip File'), ('single file', 'Single File')], default='single file', max_length=20, verbose_name='Upload type')),
                        ('combined_consent', models.BooleanField(default=False, help_text='If enabled, participants will be asked to consent to submit all uploaded data at once. Otherwise, participant will be asked to consent to the submission of the data separately for each blueprint.', verbose_name='All-in-one consent')),
                        ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ddm.donationproject')),
                    ],
                ),
                migrations.CreateModel(
                    name='DonationInstruction',
                    fields=[
                        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                        ('text', models.TextField(blank=True, null=True)),
                        ('index', models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)])),
                        ('file_uploader', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='ddm_datadonation.fileuploader', verbose_name='Associated File Uploader')),
                    ],
                    options={
                        'ordering': ['index'],
                    },
                ),
                migrations.AddField(
                    model_name='donationblueprint',
                    name='file_uploader',
                    field=models.ForeignKey(blank=True, help_text='The File Uploader through which the related file will be uploaded.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='ddm_datadonation.fileuploader', verbose_name='Associated File Uploader'),
                ),
                migrations.AddField(
                    model_name='donationblueprint',
                    name='project',
                    field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ddm.donationproject'),
                ),
                migrations.CreateModel(
                    name='DataDonation',
                    fields=[
                        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                        ('time_submitted', models.DateTimeField(default=django.utils.timezone.now)),
                        ('consent', models.BooleanField(default=False)),
                        ('status', models.JSONField()),
                        ('data', models.BinaryField()),
                        ('blueprint', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='ddm_datadonation.donationblueprint')),
                        ('participant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ddm.participant')),
                        ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ddm.donationproject')),
                    ],
                    options={
                        'abstract': False,
                    },
                ),
                migrations.AddConstraint(
                    model_name='donationinstruction',
                    constraint=models.UniqueConstraint(fields=('index', 'file_uploader'), name='unique_index_per_file_uploader'),
                ),
            ],
            # Tables already exists. See ddm/migrations/0052 and 0053.
            database_operations=[]
        )
    ]
