import bcrypt from "bcryptjs";
import { PrismaClient, UserRole } from "@prisma/client";

const prisma = new PrismaClient();

const defaultBots = [
  {
    key: "raketafon",
    name: "Raketafon",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/raketafon"
  },
  {
    key: "pobeda-1-comand",
    name: "Pobeda 1 Comand",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/pobeda-1-comand"
  },
  {
    key: "raketabas",
    name: "Raketabas",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/raketabas"
  },
  {
    key: "sol-1www",
    name: "Sol 1www",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/sol-1www"
  },
  {
    key: "fon-stb",
    name: "Fon Stb",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/fon-stb"
  },
  {
    key: "fonat",
    name: "Fonat",
    sourceUrl: "https://alpinbet.com/dispatch/antigol/fonat"
  }
];

async function main() {
  const adminPasswordHash = await bcrypt.hash("admin12345", 10);

  await prisma.user.upsert({
    where: { email: "admin@example.com" },
    update: {},
    create: {
      email: "admin@example.com",
      passwordHash: adminPasswordHash,
      role: UserRole.admin,
      notificationSetting: {
        create: {
          signalsPushEnabled: true,
          resultsPushEnabled: true
        }
      }
    }
  });

  for (const bot of defaultBots) {
    await prisma.bot.upsert({
      where: { key: bot.key },
      update: {
        name: bot.name,
        sourceUrl: bot.sourceUrl,
        active: true
      },
      create: bot
    });
  }
}

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