from django.db import migrations

# Theme applied by the frontend's InvoicePreview. `style` selects the
# structural treatment (classic/modern/minimal/bold/luxury); the colors
# are chosen dark/saturated enough to work as white-on-color text for
# the "modern" and "bold" styles, and as plain text/border accents for
# the others.
LAYOUTS = {
    'Classic Corporate': {'style': 'classic', 'primary_color': '#1c5cab', 'accent_color': '#256abf', 'font': 'sans'},
    'Minimal Mono': {'style': 'minimal', 'primary_color': '#0b0b0b', 'accent_color': '#52514e', 'font': 'sans'},
    'Modern Gradient': {'style': 'modern', 'primary_color': '#4a3aa7', 'accent_color': '#1baf7a', 'font': 'sans'},
    'Creative Bold': {'style': 'bold', 'primary_color': '#c53030', 'accent_color': '#eda100', 'font': 'sans'},
    'Legal Formal': {'style': 'classic', 'primary_color': '#0b0b0b', 'accent_color': '#52514e', 'font': 'serif'},
    'Consulting Pro': {'style': 'classic', 'primary_color': '#184f95', 'accent_color': '#1baf7a', 'font': 'sans'},
    'Luxury Gold': {'style': 'luxury', 'primary_color': '#8a6d1f', 'accent_color': '#0b0b0b', 'font': 'serif'},
    'Church Community': {'style': 'minimal', 'primary_color': '#006300', 'accent_color': '#0ca30c', 'font': 'sans'},
    'Photography Showcase': {'style': 'bold', 'primary_color': '#0b0b0b', 'accent_color': '#eb6834', 'font': 'sans'},
    'Construction Rugged': {'style': 'bold', 'primary_color': '#c25a1f', 'accent_color': '#0b0b0b', 'font': 'sans'},
}


def seed_layouts(apps, schema_editor):
    InvoiceTemplate = apps.get_model('templates', 'InvoiceTemplate')
    for name, layout in LAYOUTS.items():
        InvoiceTemplate.objects.filter(name=name).update(layout=layout)


def unseed_layouts(apps, schema_editor):
    InvoiceTemplate = apps.get_model('templates', 'InvoiceTemplate')
    InvoiceTemplate.objects.filter(name__in=LAYOUTS.keys()).update(layout={})


class Migration(migrations.Migration):
    dependencies = [
        ('templates', '0002_seed_default_templates'),
    ]

    operations = [
        migrations.RunPython(seed_layouts, unseed_layouts),
    ]
