import 'dotenv/config';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@prisma/client';

const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
const prisma = new PrismaClient({ adapter });

const BLOCKS = [
  { path: '/components/navigation', name: 'Шапка / Навигация', version: 'v1.0', isInPreview: true },
  { path: '/blocks/hero', name: 'Hero-баннер', version: 'v1.1', isInPreview: true },
  { path: '/blocks/ceo', name: 'Вводный текст (CEO-блок)', version: 'v0.1', isInPreview: false },
  { path: '/blocks/doctors', name: 'Наши врачи', version: 'v1.1', isInPreview: true },
  { path: '/blocks/reviews', name: 'Отзывы', version: 'v0.1', isInPreview: false },
  { path: '/blocks/contact-forms', name: 'Формы записи', version: 'v0.1', isInPreview: false },
  { path: '/blocks/news', name: 'Новости', version: 'v0.1', isInPreview: false },
  { path: '/blocks/contact', name: 'Подвал / Контакт', version: 'v0.1', isInPreview: false },
];

async function main() {
  for (const block of BLOCKS) {
    await prisma.block.upsert({
      where: { path: block.path },
      update: {},
      create: block,
    });
  }
  console.log(`Seeded ${BLOCKS.length} blocks`);
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(() => prisma.$disconnect());
