require("dotenv").config({ path: ".env" });
const prisma = require("../src/prisma");

async function main() {
  const users = await prisma.user.findMany({
    select: {
      id: true,
      email: true,
      fullName: true,
      activeBranchId: true,
      branches: { include: { branch: true } },
    },
    orderBy: { createdAt: "asc" },
    take: 20,
  });

  for (const u of users) {
    console.log(
      `${u.email} | activeBranchId=${u.activeBranchId || "—"} | branches=${u.branches
        .map((b) => b.branch.name)
        .join(", ")}`
    );
  }

  const branches = await prisma.branch.findMany({
    select: { id: true, name: true, code: true },
    orderBy: [{ sortOrder: "asc" }, { name: "asc" }],
  });
  console.log("Branches:", branches.map((b) => `${b.name}(${b.id})`).join(" | "));
}

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

