import { test, expect } from "@playwright/test";
import { PrismaClient } from "@prisma/client";
import { bookTrip } from "../../fixtures/booking-flow";

const prisma = new PrismaClient();
test.afterAll(async () => {
  await prisma.$disconnect();
});

/**
 * UA-16 — one-way, 2 adults + 3 children under 5, ETB, WALLET (max passenger spread). One free child
 * per adult → 2 free children, 1 paid. Total = 3 fares (2 adults + 1 paid child); 3 seats booked.
 * Stresses the free-child reduce + multi-passenger seat assignment through the real browser.
 */
test("UA-16: 2 adults + 3 children — two children free, one paid", async ({ page }) => {
  const r = await bookTrip(page, { adults: 2, children: 3, paymentMethod: "WALLET" });
  expect(r.confirmed).toBe(true);

  const fare = r.cardBaseFareMinor;
  expect(r.reviewedTotalMinor).toBe(fare * 3);

  const booking = await prisma.booking.findUniqueOrThrow({ where: { id: r.bookingId } });
  expect(booking.totalMinor).toBe(fare * 3);

  const seats = await prisma.bookingSeat.findMany({ where: { bookingId: r.bookingId } });
  expect(seats.length).toBe(3);
});
