import { config } from 'dotenv';
// Load .env.local
config({ path: '.env.local' });

const SITE_ID = process.env.SITE_ID || 'ten-sura-game.com';

async function seedFooterNav() {
  const { db } = await import('../lib/db');
  const { navigationItems } = await import('../shared/schema');
  const { and, eq } = await import('drizzle-orm');

  const links = [
    { label: '運営元について', url: '/about-us', sortOrder: 998 },
    { label: 'プライバシーポリシー', url: '/privacy-policy', sortOrder: 999 },
  ];

  for (const link of links) {
    // Check if exists
    const existing = await db.select().from(navigationItems).where(
      and(
        eq(navigationItems.siteId, SITE_ID),
        eq(navigationItems.menuLocation, 'footer'),
        eq(navigationItems.url, link.url)
      )
    );

    if (existing.length === 0) {
      await db.insert(navigationItems).values({
        siteId: SITE_ID,
        label: link.label,
        url: link.url,
        menuLocation: 'footer',
        itemType: 'custom_page',
        isActive: true,
        sortOrder: link.sortOrder,
        createdAt: new Date(),
        updatedAt: new Date(),
      });
      console.log(`Seeded footer link: ${link.label}`);
    } else {
      console.log(`Footer link already exists: ${link.label}`);
    }
  }
}

seedFooterNav().then(() => {
  console.log('Done');
  process.exit(0);
}).catch(err => {
  console.error(err);
  process.exit(1);
});
