"""
Run once from the backend folder:
    python seed_footer_links.py
"""
import sqlite3, os

db = os.path.join(os.path.dirname(__file__), 'db.sqlite3')
conn = sqlite3.connect(db)
cur = conn.cursor()

TENANT_ID = 1  # Final Target

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),
]

# Remove existing links for tenant 1 and re-insert clean
cur.execute('DELETE FROM pages_footerlink WHERE tenant_id = ?', (TENANT_ID,))
print(f'Cleared old links for tenant {TENANT_ID}')

for col, label, url, target, order in LINKS:
    cur.execute(
        'INSERT INTO pages_footerlink ("column", label, url, target, "order", is_active, tenant_id) '
        'VALUES (?, ?, ?, ?, ?, 1, ?)',
        (col, label, url, target, order, TENANT_ID)
    )

conn.commit()
print(f'Done — inserted {len(LINKS)} footer links for tenant {TENANT_ID}')

# Verify
cur.execute('SELECT "column", label, url FROM pages_footerlink WHERE tenant_id=? ORDER BY "column", "order"', (TENANT_ID,))
for r in cur.fetchall():
    print(' ', r)

conn.close()
