from django.db import migrations


SEED_LINKS = [
    # (column, label, url, target, order)
    ('who_we_are', 'About Us',      '/#about',                                              '_self',  0),
    ('who_we_are', 'Career',        'https://www.linkedin.com/company/FinalTarget/jobs',    '_blank', 1),
    ('who_we_are', 'Portfolio',     '/portfolio/',                                           '_self',  2),
    ('who_we_are', 'Insights',      '/insights/',                                            '_self',  3),
    ('who_we_are', 'Support & FAQ', '/faq/',                                                 '_self',  4),
    ('who_we_are', 'Contact',       '/contact/',                                             '_self',  5),

    ('products', 'Premium Domains',        '/shop/', '_self', 0),
    ('products', 'AI Products',            '/shop/', '_self', 1),
    ('products', 'Templates & Resources',  '/shop/', '_self', 2),
    ('products', 'Business Starter Kits',  '/shop/', '_self', 3),
    ('products', 'Software',               '/shop/', '_self', 4),
    ('products', 'Marketplace',            '/shop/', '_self', 5),

    ('services', 'Digital Transformation', '/services/digital-transformation/', '_self', 0),
    ('services', 'Software Development',   '/services/',                        '_self', 1),
    ('services', 'AI Solutions',           '/services/ai-solutions/',           '_self', 2),
    ('services', 'Web & App Development',  '/services/',                        '_self', 3),
    ('services', 'Growth Marketing',       '/services/',                        '_self', 4),
    ('services', 'Support & Maintenance',  '/services/',                        '_self', 5),

    ('subscriptions', 'FT Panel',        '/shop/', '_self', 0),
    ('subscriptions', 'FT Ads',          '/shop/', '_self', 1),
    ('subscriptions', 'FT BizHub',       '/shop/', '_self', 2),
    ('subscriptions', 'Hosting & Cloud', '/shop/', '_self', 3),
    ('subscriptions', 'Business Email',  '/shop/', '_self', 4),
    ('subscriptions', 'Website Care',    '/shop/', '_self', 5),
]


def seed_footer_links(apps, schema_editor):
    FooterLink = apps.get_model('pages', 'FooterLink')
    Tenant     = apps.get_model('tenants', 'Tenant')

    # Only seed if table is empty (don't double-insert on re-runs)
    if FooterLink.objects.exists():
        return

    tenant = Tenant.objects.first()  # single-tenant dev setup

    for column, label, url, target, order in SEED_LINKS:
        FooterLink.objects.create(
            tenant=tenant,
            column=column,
            label=label,
            url=url,
            target=target,
            order=order,
            is_active=True,
        )


def unseed_footer_links(apps, schema_editor):
    FooterLink = apps.get_model('pages', 'FooterLink')
    FooterLink.objects.all().delete()


class Migration(migrations.Migration):

    dependencies = [
        ('pages', '0011_footerlink_target'),
        ('tenants', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(seed_footer_links, unseed_footer_links),
    ]
