// One-off helper: add more approved questions to the CCNA 200-301 exam
// so the 5-free-question paywall is easy to demonstrate.
//   node prisma/addCcnaQuestions.js
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

const MORE = [
  {
    text: 'Which Cisco IOS command saves the running configuration to NVRAM?',
    explanation: '"copy running-config startup-config" (or "write memory") saves the config to NVRAM.',
    type: 'SINGLE',
    options: [
      { text: 'copy startup-config running-config', isCorrect: false },
      { text: 'copy running-config startup-config', isCorrect: true },
      { text: 'save config', isCorrect: false },
      { text: 'reload', isCorrect: false },
    ],
  },
  {
    text: 'What is the broadcast address of the network 192.168.10.0/24?',
    explanation: 'For a /24, the broadcast address is the last address: 192.168.10.255.',
    type: 'SINGLE',
    options: [
      { text: '192.168.10.0', isCorrect: false },
      { text: '192.168.10.1', isCorrect: false },
      { text: '192.168.10.254', isCorrect: false },
      { text: '192.168.10.255', isCorrect: true },
    ],
  },
  {
    text: 'Which two devices operate primarily at Layer 2 of the OSI model? (Choose two.)',
    explanation: 'Switches and bridges forward frames using MAC addresses at Layer 2.',
    type: 'MULTIPLE',
    options: [
      { text: 'Switch', isCorrect: true },
      { text: 'Router', isCorrect: false },
      { text: 'Bridge', isCorrect: true },
      { text: 'Firewall (Layer 3/4)', isCorrect: false },
    ],
  },
  {
    text: 'Which protocol resolves an IP address to a MAC address?',
    explanation: 'ARP (Address Resolution Protocol) maps an IPv4 address to a MAC address.',
    type: 'SINGLE',
    options: [
      { text: 'DNS', isCorrect: false },
      { text: 'ARP', isCorrect: true },
      { text: 'ICMP', isCorrect: false },
      { text: 'DHCP', isCorrect: false },
    ],
  },
  {
    text: 'What is the administrative distance of a directly connected route?',
    explanation: 'Directly connected routes have the most trusted administrative distance of 0.',
    type: 'SINGLE',
    options: [
      { text: '0', isCorrect: true },
      { text: '1', isCorrect: false },
      { text: '90', isCorrect: false },
      { text: '110', isCorrect: false },
    ],
  },
  {
    text: 'Which port does SSH use by default?',
    explanation: 'SSH uses TCP port 22 by default.',
    type: 'SINGLE',
    options: [
      { text: '22', isCorrect: true },
      { text: '23', isCorrect: false },
      { text: '80', isCorrect: false },
      { text: '443', isCorrect: false },
    ],
  },
  {
    text: 'In which switchport mode does an interface actively try to form a trunk?',
    explanation: 'DTP "dynamic desirable" actively negotiates a trunk; "trunk" forces it on.',
    type: 'SINGLE',
    options: [
      { text: 'access', isCorrect: false },
      { text: 'dynamic auto', isCorrect: false },
      { text: 'dynamic desirable', isCorrect: true },
      { text: 'nonegotiate', isCorrect: false },
    ],
  },
  {
    text: 'Which IPv6 address type is equivalent to a private IPv4 address?',
    explanation: 'Unique Local Addresses (FC00::/7, commonly FD00::/8) are the IPv6 equivalent of private addresses.',
    type: 'SINGLE',
    options: [
      { text: 'Global Unicast', isCorrect: false },
      { text: 'Link-Local (FE80::/10)', isCorrect: false },
      { text: 'Unique Local (FC00::/7)', isCorrect: true },
      { text: 'Multicast (FF00::/8)', isCorrect: false },
    ],
  },
];

async function main() {
  const course = await prisma.course.findUnique({ where: { slug: 'cisco-ccna-200-301' } });
  if (!course) throw new Error('CCNA course not found — run npm run seed first.');

  const start = await prisma.question.count({ where: { courseId: course.id } });

  for (let i = 0; i < MORE.length; i++) {
    const q = MORE[i];
    // skip if a question with the same text already exists (idempotent)
    const exists = await prisma.question.findFirst({ where: { courseId: course.id, text: q.text } });
    if (exists) continue;
    await prisma.question.create({
      data: {
        courseId: course.id,
        text: q.text,
        explanation: q.explanation,
        type: q.type,
        status: 'APPROVED',
        order: start + i,
        options: { create: q.options.map((o, idx) => ({ ...o, order: idx })) },
      },
    });
  }

  const total = await prisma.question.count({ where: { courseId: course.id } });
  console.log(`CCNA 200-301 now has ${total} approved questions.`);
}

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