# Generated by Django 2.2.6 on 2020-01-13 17:12

import datetime
from django.db import migrations, models
import django.db.models.deletion
from django.utils.timezone import utc
from django.utils.timezone import get_current_timezone
from django.utils.dateparse import parse_datetime

import random

# pylint: disable=all


def populate(apps, schema_editor):
    tz = get_current_timezone()

    crops = []
    crop_model = apps.get_model('crop', 'Crop')
    crops.append(crop_model.objects.create(name='Greek', family='Basil'))
    crops.append(crop_model.objects.create(
        name='Sweet Genovese', family='Basil'))
    crops.append(crop_model.objects.create(
        name='Nicola (CN GBAS 5033)', family='Basil'))
    crops.append(crop_model.objects.create(
        name='Fine Leaved', family='Chives'))
    crops.append(crop_model.objects.create(
        name='Fine Leaved', family='Chives'))
    crops.append(crop_model.objects.create(name='Garlic', family='chives'))

    plans = []
    plan_model = apps.get_model('crop', 'GrowthPlan')
    plans.append(plan_model.objects.create(
        crop=crops[0], name='Micro', growth_duration=8, est_yield=80))
    plans.append(plan_model.objects.create(
        crop=crops[0], name='Large', growth_duration=32, est_yield=320))
    plans.append(plan_model.objects.create(
        crop=crops[1], name='Micro', growth_duration=11, est_yield=70))
    plans.append(plan_model.objects.create(
        crop=crops[1], name='Large', growth_duration=27, est_yield=290))
    plans.append(plan_model.objects.create(
        crop=crops[4], name='Default', growth_duration=22, est_yield=235))
    plans.append(plan_model.objects.create(
        crop=crops[5], name='Test', growth_duration=45, est_yield=0))

    tray_model = apps.get_model('crop', 'Tray')
    for _ in range(20):
        tray_model.objects.create(
            crop=crops[3], growth_plan=plans[4], sow_date=tz.localize(parse_datetime('2020-1-1T12:00:00')))
    for _ in range(20):
        value = random.randint(-20, 20)+80
        tray_model.objects.create(
            crop=crops[0], growth_plan=plans[0], sow_date=tz.localize(parse_datetime('2020-1-3T14:00:00')), harvest_date=tz.localize(parse_datetime('2020-1-11T13:00:00')), total_yield=value)
    for _ in range(20):
        value = random.randint(-30, 30)+290
        tray_model.objects.create(crop=crops[1], growth_plan=plans[3], sow_date=tz.localize(parse_datetime('2019-12-1T11:00:00')),
                                  harvest_date=tz.localize(parse_datetime('2019-12-23T16:00:00')), total_yield=value)
    for _ in range(20):
        tray_model.objects.create(
            crop=crops[5], growth_plan=plans[5], sow_date=tz.localize(parse_datetime('2020-1-22T12:00:00')))
    for _ in range(20):
        value = random.randint(-40, 40)+320
        tray_model.objects.create(
            crop=crops[0], growth_plan=plans[1], sow_date=tz.localize(parse_datetime('2019-11-7T12:00:00')), harvest_date=tz.localize(parse_datetime('2019-12-1T12:00:00')), total_yield=value)
    for _ in range(20):
        value = random.randint(-10, 10)+70
        tray_model.objects.create(crop=crops[1], growth_plan=plans[2], sow_date=tz.localize(parse_datetime('2019-11-21T12:00:00')),
                                  harvest_date=tz.localize(parse_datetime('2019-11-21T12:00:00')), total_yield=value)
    for _ in range(20):
        value = random.randint(-30, 30)+235
        tray_model.objects.create(
            crop=crops[3], growth_plan=plans[4], sow_date=tz.localize(parse_datetime('2021-1-3T12:00:00')), total_yield=value)
    for _ in range(20):
        value = random.randint(-30, 30)+235
        tray_model.objects.create(crop=crops[1], growth_plan=plans[3], sow_date=tz.localize(parse_datetime('2019-12-3T12:00:00')),
                                  harvest_date=tz.localize(parse_datetime('2019-11-10T12:00:00')), total_yield=value)


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Crop',
            fields=[
                ('id', models.AutoField(auto_created=True,
                                        primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('family', models.CharField(max_length=100)),
            ],
        ),
        migrations.CreateModel(
            name='GrowthPlan',
            fields=[
                ('id', models.AutoField(auto_created=True,
                                        primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50)),
                ('growth_duration', models.IntegerField()),
                ('est_yield', models.IntegerField()),
                ('crop', models.ForeignKey(
                    on_delete=django.db.models.deletion.PROTECT, to='crop.Crop')),
            ],
        ),
        migrations.CreateModel(
            name='Tray',
            fields=[
                ('id', models.AutoField(auto_created=True,
                                        primary_key=True, serialize=False, verbose_name='ID')),
                ('sow_date', models.DateTimeField(default=datetime.datetime(
                    2020, 1, 13, 17, 12, 18, 817011, tzinfo=utc))),
                ('harvest_date', models.DateTimeField(null=True)),
                ('total_yield', models.IntegerField(default=0)),
                ('crop', models.ForeignKey(
                    on_delete=django.db.models.deletion.PROTECT, to='crop.Crop')),
                ('growth_plan', models.ForeignKey(
                    on_delete=django.db.models.deletion.PROTECT, to='crop.GrowthPlan')),
            ],
        ),
        migrations.RunPython(populate),
    ]
