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

const prisma = new PrismaClient();

async function hash(password: string) {
  return bcrypt.hash(password, 10);
}

type MemberSeed = {
  email: string;
  name: string;
  role: string;
  verificationStatus: string;
  wholesaleStatus: string;
  featured?: boolean;
  profile: {
    type: string;
    company?: string;
    location: string;
    country: string;
    bio: string;
    specialties: string;
    originFocus: string;
    yearsInTrade: string;
    labs?: string;
    photoUrl: string;
  };
};

const PEOPLE: MemberSeed[] = [
  {
    email: "sofia@emeraldcoast.example",
    name: "Sofia Reyes",
    role: "wholesale",
    verificationStatus: "approved",
    wholesaleStatus: "approved",
    featured: true,
    profile: {
      type: "dealer",
      company: "Emerald Coast Trading",
      location: "Bogotá",
      country: "Colombia",
      bio: "Family office specializing in Colombian emeralds for private clients and cutters.",
      specialties: "Colombian emeralds, calibrated pairs",
      originFocus: "Muzo, Chivor",
      yearsInTrade: "18",
      photoUrl: "/media/people/sofia.jpg",
    },
  },
  {
    email: "kenji@facetstudio.example",
    name: "Kenji Okada",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    featured: true,
    profile: {
      type: "cutter",
      company: "Okada Facet Studio",
      location: "Bangkok",
      country: "Thailand",
      bio: "Precision sapphire and ruby cutting. Recuts, custom pavilions, collector finishes.",
      specialties: "Sapphire cutting, recuts",
      originFocus: "Sri Lanka, Madagascar",
      yearsInTrade: "12",
      labs: "AIGS, GIA alumni",
      photoUrl: "/media/people/kenji.jpg",
    },
  },
  {
    email: "aisha@sahelmines.example",
    name: "Aisha Diallo",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "pending",
    featured: true,
    profile: {
      type: "miner",
      company: "Sahel Source",
      location: "Antananarivo",
      country: "Madagascar",
      bio: "Mine-to-cutter supply of sapphire and garnet. Ethical sourcing notes on every parcel.",
      specialties: "Sapphire rough, garnet",
      originFocus: "Madagascar",
      yearsInTrade: "9",
      photoUrl: "/media/people/aisha.jpg",
    },
  },
  {
    email: "marcus@ateliercollect.example",
    name: "Marcus Chen",
    role: "member",
    verificationStatus: "pending",
    wholesaleStatus: "none",
    profile: {
      type: "collector",
      location: "Singapore",
      country: "Singapore",
      bio: "Collector of untreated stones with documented origin. Looking for a trusted cutter.",
      specialties: "Untreated sapphires",
      originFocus: "Kashmir, Ceylon",
      yearsInTrade: "4",
      photoUrl: "/media/people/marcus.jpg",
    },
  },
  {
    email: "lab@gia-partner.example",
    name: "North Lab Liaison",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "lab",
      company: "North Gem Lab",
      location: "Hong Kong",
      country: "Hong Kong",
      bio: "Origin and treatment reports for trade clients. Fast-track for network members.",
      specialties: "Origin reports, treatment disclosure",
      originFocus: "Global",
      yearsInTrade: "15",
      labs: "Independent",
      photoUrl: "/media/people/lab.jpg",
    },
  },
  {
    email: "lucia@jaipuratelier.example",
    name: "Lucia Mehta",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    featured: true,
    profile: {
      type: "jeweler",
      company: "Jaipur Atelier",
      location: "Jaipur",
      country: "India",
      bio: "Commission jewellery for private clients. Buys calibrated colour and one-off sapphires.",
      specialties: "High jewellery, calibrated colour",
      originFocus: "India, Sri Lanka",
      yearsInTrade: "14",
      photoUrl: "/media/people/lucia.jpg",
    },
  },
  {
    email: "ravi@paloma.example",
    name: "Ravi Paloma",
    role: "wholesale",
    verificationStatus: "approved",
    wholesaleStatus: "approved",
    featured: true,
    profile: {
      type: "dealer",
      company: "Paloma Colour House",
      location: "Jaipur",
      country: "India",
      bio: "Dealer in fancy sapphires and spinel. Trays by appointment for verified members.",
      specialties: "Fancy sapphires, spinel",
      originFocus: "Sri Lanka, Tanzania, Madagascar",
      yearsInTrade: "22",
      photoUrl: "/media/people/ravi.jpg",
    },
  },
  {
    email: "elena@cabinetbleu.example",
    name: "Elena Moreau",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "collector",
      company: "Cabinet Bleu",
      location: "Paris",
      country: "France",
      bio: "Cabinet collector. Prefers no-heat corundum with older lab papers.",
      specialties: "No-heat sapphire, padparadscha",
      originFocus: "Kashmir, Burma, Ceylon",
      yearsInTrade: "11",
      photoUrl: "/media/people/elena.jpg",
    },
  },
  {
    email: "pierre@escaut.example",
    name: "Pierre Declerck",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "pending",
    profile: {
      type: "dealer",
      company: "Escaut Gems",
      location: "Antwerp",
      country: "Belgium",
      bio: "Diamond and coloured-stone broker. Quiet parcels for European ateliers.",
      specialties: "Diamond melee, coloured pairs",
      originFocus: "Africa, Brazil",
      yearsInTrade: "16",
      photoUrl: "/media/people/pierre.jpg",
    },
  },
  {
    email: "yuki@kintsugi.example",
    name: "Yuki Nakamura",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "jeweler",
      company: "Kintsugi Studio",
      location: "Tokyo",
      country: "Japan",
      bio: "Small-run jewellery. Buys unusual cuts and leftover calibrated lots.",
      specialties: "Unusual cuts, spinel",
      originFocus: "Tanzania, Vietnam",
      yearsInTrade: "8",
      photoUrl: "/media/people/yuki.jpg",
    },
  },
  {
    email: "hassan@rukwa.example",
    name: "Hassan Mwamba",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "miner",
      company: "Rukwa Source",
      location: "Dodoma",
      country: "Tanzania",
      bio: "Mahenge spinel and Umba sapphire. Origin notes and crystal photos with every parcel.",
      specialties: "Spinel, Umba sapphire",
      originFocus: "Mahenge, Umba",
      yearsInTrade: "10",
      photoUrl: "/media/people/hassan.jpg",
    },
  },
  {
    email: "claire@idarbench.example",
    name: "Claire Hoffmann",
    role: "wholesale",
    verificationStatus: "approved",
    wholesaleStatus: "approved",
    profile: {
      type: "cutter",
      company: "Idar Bench",
      location: "Idar-Oberstein",
      country: "Germany",
      bio: "German cutting house. Recuts, fantasy cuts, and museum work.",
      specialties: "Fantasy cuts, recuts",
      originFocus: "Brazil, Africa",
      yearsInTrade: "19",
      labs: "DSEF affiliated",
      photoUrl: "/media/people/claire.jpg",
    },
  },
  {
    email: "diego@minasfacet.example",
    name: "Diego Alves",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "cutter",
      company: "Minas Facet",
      location: "Belo Horizonte",
      country: "Brazil",
      bio: "Tourmaline, aquamarine, and imperial topaz cutting. Parcel work for jewelers.",
      specialties: "Tourmaline, aquamarine",
      originFocus: "Minas Gerais",
      yearsInTrade: "13",
      photoUrl: "/media/people/diego.jpg",
    },
  },
  {
    email: "noor@gulforigin.example",
    name: "Noor Al-Hassan",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "none",
    profile: {
      type: "lab",
      company: "Gulf Origin Lab",
      location: "Dubai",
      country: "UAE",
      bio: "Origin and treatment reports with a 72-hour turnaround for network members.",
      specialties: "Origin, heat disclosure",
      originFocus: "Global",
      yearsInTrade: "7",
      labs: "ISO independent",
      photoUrl: "/media/people/noor.jpg",
    },
  },
  {
    email: "thomas@mayfair.example",
    name: "Thomas Ellison",
    role: "member",
    verificationStatus: "pending",
    wholesaleStatus: "none",
    profile: {
      type: "collector",
      location: "London",
      country: "United Kingdom",
      bio: "New to the floor. Collecting Ceylon sapphires under 3 ct with papers.",
      specialties: "Ceylon sapphires",
      originFocus: "Sri Lanka",
      yearsInTrade: "2",
      photoUrl: "/media/people/thomas.jpg",
    },
  },
  {
    email: "amara@volta.example",
    name: "Amara Mensah",
    role: "verified",
    verificationStatus: "approved",
    wholesaleStatus: "pending",
    profile: {
      type: "dealer",
      company: "Volta Colour",
      location: "Accra",
      country: "Ghana",
      bio: "West African garnet and diamond melee for European workshops.",
      specialties: "Garnet, diamond melee",
      originFocus: "Ghana, Namibia",
      yearsInTrade: "11",
      photoUrl: "/media/people/amara.jpg",
    },
  },
  {
    email: "jonas@atelierrow.example",
    name: "Jonas Hale",
    role: "member",
    verificationStatus: "pending",
    wholesaleStatus: "none",
    profile: {
      type: "jeweler",
      company: "Atelier Row",
      location: "New York",
      country: "United States",
      bio: "Independent jeweler. Looking for a trusted sapphire cutter and a melee source.",
      specialties: "Custom rings, melee",
      originFocus: "Sri Lanka, Colombia",
      yearsInTrade: "6",
      photoUrl: "/media/people/jonas.jpg",
    },
  },
];

async function main() {
  await prisma.bid.deleteMany();
  await prisma.offer.deleteMany();
  await prisma.message.deleteMany();
  await prisma.threadParticipant.deleteMany();
  await prisma.thread.deleteMany();
  await prisma.follow.deleteMany();
  await prisma.reply.deleteMany();
  await prisma.post.deleteMany();
  await prisma.report.deleteMany();
  await prisma.wholesaleOrder.deleteMany();
  await prisma.listing.deleteMany();
  await prisma.auction.deleteMany();
  await prisma.wholesaleLot.deleteMany();
  await prisma.profile.deleteMany();
  await prisma.user.deleteMany();

  const password = await hash("ElbeeGems!dev");

  const admin = await prisma.user.create({
    data: {
      email: "admin@elbeegems.com",
      passwordHash: password,
      name: "ElbeeGems Trust",
      role: "admin",
      verificationStatus: "approved",
      wholesaleStatus: "approved",
      featured: true,
      profile: {
        create: {
          type: "company",
          company: "ElbeeGems",
          location: "",
          country: "United States",
          bio: "Steward of the floor — wholesale, auctions, and the trusted gem network.",
          specialties: "Hand-cut gemstones, private wholesale, weekly auctions",
          originFocus: "Global",
          yearsInTrade: "20+",
          photoUrl: "/media/people/admin.jpg",
        },
      },
    },
  });

  const created = await Promise.all(
    PEOPLE.map((person) =>
      prisma.user.create({
        data: {
          email: person.email,
          passwordHash: password,
          name: person.name,
          role: person.role,
          verificationStatus: person.verificationStatus,
          wholesaleStatus: person.wholesaleStatus,
          featured: Boolean(person.featured),
          profile: { create: person.profile },
        },
      }),
    ),
  );

  const byEmail = Object.fromEntries(created.map((user) => [user.email, user]));
  const sofia = byEmail["sofia@emeraldcoast.example"];
  const kenji = byEmail["kenji@facetstudio.example"];
  const aisha = byEmail["aisha@sahelmines.example"];
  const marcus = byEmail["marcus@ateliercollect.example"];
  const lab = byEmail["lab@gia-partner.example"];
  const lucia = byEmail["lucia@jaipuratelier.example"];
  const ravi = byEmail["ravi@paloma.example"];
  const elena = byEmail["elena@cabinetbleu.example"];
  const pierre = byEmail["pierre@escaut.example"];
  const yuki = byEmail["yuki@kintsugi.example"];
  const hassan = byEmail["hassan@rukwa.example"];
  const claire = byEmail["claire@idarbench.example"];
  const diego = byEmail["diego@minasfacet.example"];
  const noor = byEmail["noor@gulforigin.example"];
  const thomas = byEmail["thomas@mayfair.example"];
  const amara = byEmail["amara@volta.example"];
  const jonas = byEmail["jonas@atelierrow.example"];

  await prisma.listing.createMany({
    data: [
      {
        sellerId: kenji.id,
        title: "Ceylon sapphire, 3.21 ct",
        gemType: "sapphire",
        origin: "Sri Lanka",
        weightCt: 3.21,
        color: "Cornflower blue",
        treatment: "Unheated",
        clarity: "Eye clean",
        certification: "GRS",
        cut: "Oval",
        dimensions: "9.8 × 7.4 × 5.1",
        askingPrice: 12800,
        marketLow: 11000,
        marketHigh: 14500,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "KO-SAP-321",
        notes: "No heat. Strong colour in LED and daylight. Recut pavilion, window closed.",
      },
      {
        sellerId: kenji.id,
        title: "Padparadscha sapphire, 2.14 ct",
        gemType: "sapphire",
        origin: "Sri Lanka",
        weightCt: 2.14,
        color: "Pink-orange",
        treatment: "Unheated",
        clarity: "VS",
        certification: "GRS",
        cut: "Cushion",
        dimensions: "7.6 × 6.9 × 4.8",
        askingPrice: 9600,
        marketLow: 8200,
        marketHigh: 11000,
        availability: "hold",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "KO-PAD-214",
        notes: "Held for a ring brief. Colour holds under both lights. Papers in the room.",
      },
      {
        sellerId: ravi.id,
        title: "Royal blue sapphire, 4.08 ct",
        gemType: "sapphire",
        origin: "Madagascar",
        weightCt: 4.08,
        color: "Royal blue",
        treatment: "Heat",
        clarity: "Eye clean",
        certification: "AIGS",
        cut: "Oval",
        dimensions: "10.4 × 8.1 × 5.6",
        askingPrice: 6400,
        marketLow: 5800,
        marketHigh: 7800,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "PC-SAP-408",
        notes: "Standard heat. Calibrated for a high-jewellery client. Clean pavilion.",
      },
      {
        sellerId: ravi.id,
        title: "Umba sapphire, 1.86 ct",
        gemType: "sapphire",
        origin: "Tanzania",
        weightCt: 1.86,
        color: "Teal",
        treatment: "Unheated",
        clarity: "VS",
        certification: "AIGS",
        cut: "Emerald",
        dimensions: "8.2 × 6.1 × 4.2",
        askingPrice: 2100,
        marketLow: 1800,
        marketHigh: 2600,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "PC-UMB-186",
        notes: "Umba teal with a clean table. Good for a collector ring under 2 ct.",
      },
      {
        sellerId: aisha.id,
        title: "Madagascar sapphire parcel, 12.4 ct",
        gemType: "sapphire",
        origin: "Madagascar",
        weightCt: 12.4,
        color: "Mixed blues",
        treatment: "Heat",
        clarity: "VS–SI",
        certification: "Seller memo",
        cut: "Mixed ovals",
        dimensions: "6–8 mm",
        askingPrice: 3200,
        marketLow: 2800,
        marketHigh: 3800,
        availability: "available",
        wholesaleOnly: true,
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "SS-PAR-124",
        notes: "Trade parcel. Heat disclosed. Photos and weights in the memo.",
      },
      {
        sellerId: elena.id,
        title: "Kashmir-type sapphire, 2.62 ct",
        gemType: "sapphire",
        origin: "Kashmir",
        weightCt: 2.62,
        color: "Velvety blue",
        treatment: "Unheated",
        clarity: "VS",
        certification: "Gübelin",
        cut: "Cushion",
        dimensions: "8.1 × 7.4 × 5.0",
        askingPrice: 42000,
        marketLow: 36000,
        marketHigh: 48000,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "CB-KAS-262",
        notes: "Older Gübelin paper. Velvet, no heat. Cabinet piece, not a workshop stone.",
      },
      {
        sellerId: lucia.id,
        title: "Mozambique ruby, 1.92 ct",
        gemType: "ruby",
        origin: "Mozambique",
        weightCt: 1.92,
        color: "Vivid red",
        treatment: "Heat",
        clarity: "Eye clean",
        certification: "GRS",
        cut: "Oval",
        dimensions: "8.0 × 6.2 × 4.1",
        askingPrice: 7800,
        marketLow: 7200,
        marketHigh: 9100,
        availability: "available",
        imageUrl: "/media/lots/ruby.jpg",
        sku: "JA-RBY-192",
        notes: "Heat only. Strong red for a centre stone. Matches a calibrated pair on request.",
      },
      {
        sellerId: lucia.id,
        title: "Burma ruby, 1.18 ct",
        gemType: "ruby",
        origin: "Myanmar",
        weightCt: 1.18,
        color: "Pigeon blood",
        treatment: "Unheated",
        clarity: "VS",
        certification: "GRS",
        cut: "Cushion",
        dimensions: "6.4 × 5.8 × 3.9",
        askingPrice: 18500,
        marketLow: 16000,
        marketHigh: 21000,
        availability: "available",
        imageUrl: "/media/lots/ruby.jpg",
        sku: "JA-RBY-118",
        notes: "No heat. Small but saturated. Private-client brief, not a parcel stone.",
      },
      {
        sellerId: sofia.id,
        title: "Muzo emerald, 3.40 ct",
        gemType: "emerald",
        origin: "Colombia",
        weightCt: 3.4,
        color: "Vivid green",
        treatment: "Minor oil",
        clarity: "VS",
        certification: "Gübelin",
        cut: "Emerald",
        dimensions: "10.2 × 8.4 × 5.5",
        askingPrice: 24600,
        marketLow: 22000,
        marketHigh: 28000,
        availability: "available",
        imageUrl: "/media/lots/emerald.jpg",
        sku: "EC-EM-340",
        notes: "Minor oil only. Garden is typical Muzo. Face-up colour is even.",
      },
      {
        sellerId: sofia.id,
        title: "Chivor emerald pair, 2.08 ct tw",
        gemType: "emerald",
        origin: "Colombia",
        weightCt: 2.08,
        color: "Bluish green",
        treatment: "Minor oil",
        clarity: "Eye clean",
        certification: "SSEF",
        cut: "Oval pair",
        dimensions: "6.5 × 5.0 matched",
        askingPrice: 8900,
        marketLow: 8000,
        marketHigh: 10500,
        availability: "available",
        imageUrl: "/media/lots/emerald.jpg",
        sku: "EC-EM-208P",
        notes: "Matched pair for earrings. Minor oil. Colour holds in daylight.",
      },
      {
        sellerId: sofia.id,
        title: "Muzo melee lot — trade only",
        gemType: "emerald",
        origin: "Colombia",
        weightCt: 8.6,
        color: "Medium green",
        treatment: "Minor oil",
        clarity: "SI",
        certification: "Seller memo",
        cut: "Calibrated",
        dimensions: "3–4 mm",
        askingPrice: 1900,
        marketLow: 1600,
        marketHigh: 2300,
        availability: "available",
        wholesaleOnly: true,
        imageUrl: "/media/lots/emerald.jpg",
        sku: "EC-MEL-086",
        notes: "Wholesale melee. Oil disclosed. Counts and sizes in the memo.",
      },
      {
        sellerId: hassan.id,
        title: "Mahenge spinel, 2.04 ct",
        gemType: "spinel",
        origin: "Tanzania",
        weightCt: 2.04,
        color: "Neon pink",
        treatment: "None",
        clarity: "Eye clean",
        certification: "AIGS",
        cut: "Cushion",
        dimensions: "7.4 × 6.8 × 4.6",
        askingPrice: 4200,
        marketLow: 3600,
        marketHigh: 4800,
        availability: "available",
        imageUrl: "/media/lots/spinel.jpg",
        sku: "RK-SPN-204",
        notes: "No treatment. Neon in LED. Crystal photos available before a room.",
      },
      {
        sellerId: hassan.id,
        title: "Mahenge spinel, 3.55 ct",
        gemType: "spinel",
        origin: "Tanzania",
        weightCt: 3.55,
        color: "Hot pink",
        treatment: "None",
        clarity: "VS",
        certification: "GRS",
        cut: "Oval",
        dimensions: "10.1 × 7.6 × 5.2",
        askingPrice: 9100,
        marketLow: 8400,
        marketHigh: 10800,
        availability: "available",
        imageUrl: "/media/lots/spinel.jpg",
        sku: "RK-SPN-355",
        notes: "Larger Mahenge. Slight silk. Colour is the story.",
      },
      {
        sellerId: yuki.id,
        title: "Grey-violet spinel, 1.44 ct",
        gemType: "spinel",
        origin: "Tanzania",
        weightCt: 1.44,
        color: "Grey-violet",
        treatment: "None",
        clarity: "Eye clean",
        certification: "Seller memo",
        cut: "Fantasy",
        dimensions: "7.2 × 6.0 × 4.1",
        askingPrice: 980,
        marketLow: 800,
        marketHigh: 1200,
        availability: "available",
        imageUrl: "/media/lots/spinel.jpg",
        sku: "KS-SPN-144",
        notes: "Unusual cut for a small-run jewel. No treatment.",
      },
      {
        sellerId: diego.id,
        title: "Paraíba-type tourmaline, 2.30 ct",
        gemType: "tourmaline",
        origin: "Brazil",
        weightCt: 2.3,
        color: "Neon teal",
        treatment: "Heat",
        clarity: "SI",
        certification: "AGL",
        cut: "Oval",
        dimensions: "9.2 × 6.8 × 4.7",
        askingPrice: 5400,
        marketLow: 4800,
        marketHigh: 6400,
        availability: "available",
        imageUrl: "/media/lots/tourmaline.jpg",
        sku: "MF-TRM-230",
        notes: "Heat disclosed. Copper-bearing. Window is small; recut optional.",
      },
      {
        sellerId: diego.id,
        title: "Minas tourmaline parcel, 18.2 ct",
        gemType: "tourmaline",
        origin: "Brazil",
        weightCt: 18.2,
        color: "Greens and teals",
        treatment: "Heat",
        clarity: "VS–SI",
        certification: "Seller memo",
        cut: "Mixed",
        dimensions: "Parcel",
        askingPrice: 2400,
        marketLow: 2100,
        marketHigh: 2900,
        availability: "available",
        wholesaleOnly: true,
        imageUrl: "/media/lots/tourmaline.jpg",
        sku: "MF-TRM-182P",
        notes: "Workshop parcel. Heat disclosed. Better as calibrated colour than as singles.",
      },
      {
        sellerId: diego.id,
        title: "Aquamarine, 6.10 ct",
        gemType: "aquamarine",
        origin: "Brazil",
        weightCt: 6.1,
        color: "Santa Maria blue",
        treatment: "Heat",
        clarity: "Eye clean",
        certification: "Seller memo",
        cut: "Emerald",
        dimensions: "12.4 × 9.1 × 6.2",
        askingPrice: 1850,
        marketLow: 1600,
        marketHigh: 2300,
        availability: "available",
        imageUrl: "/media/lots/tourmaline.jpg",
        sku: "MF-AQ-610",
        notes: "Standard heat. Clean and bright. Pendant size.",
      },
      {
        sellerId: amara.id,
        title: "Rhodolite garnet, 4.72 ct",
        gemType: "garnet",
        origin: "Tanzania",
        weightCt: 4.72,
        color: "Raspberry",
        treatment: "None",
        clarity: "Eye clean",
        certification: "Seller memo",
        cut: "Oval",
        dimensions: "11.0 × 8.4 × 5.8",
        askingPrice: 620,
        marketLow: 480,
        marketHigh: 780,
        availability: "available",
        imageUrl: "/media/lots/garnet.jpg",
        sku: "VC-GAR-472",
        notes: "No treatment. Even colour. Good workshop stone.",
      },
      {
        sellerId: amara.id,
        title: "Tsavorite, 1.55 ct",
        gemType: "garnet",
        origin: "Tanzania",
        weightCt: 1.55,
        color: "Vivid green",
        treatment: "None",
        clarity: "VS",
        certification: "AIGS",
        cut: "Cushion",
        dimensions: "6.8 × 6.2 × 4.4",
        askingPrice: 2400,
        marketLow: 2100,
        marketHigh: 2800,
        availability: "available",
        imageUrl: "/media/lots/garnet.jpg",
        sku: "VC-TSA-155",
        notes: "No treatment. Saturated. Better than the rhodolite tray.",
      },
      {
        sellerId: pierre.id,
        title: "Old-cut diamond, 0.92 ct",
        gemType: "diamond",
        origin: "Unknown",
        weightCt: 0.92,
        color: "J",
        treatment: "None",
        clarity: "VS2",
        certification: "GIA",
        cut: "Old cushion",
        dimensions: "6.1 × 5.8 × 3.9",
        askingPrice: 2200,
        marketLow: 1900,
        marketHigh: 2600,
        availability: "available",
        imageUrl: "/media/lots/diamond.jpg",
        sku: "EG-DIA-092",
        notes: "Old make. GIA report. Quiet stone for an atelier ring.",
      },
      {
        sellerId: pierre.id,
        title: "Diamond melee parcel, 2.40 ct",
        gemType: "diamond",
        origin: "Unknown",
        weightCt: 2.4,
        color: "G–H",
        treatment: "None",
        clarity: "VS",
        certification: "Seller memo",
        cut: "Round 1.3 mm",
        dimensions: "1.3 mm",
        askingPrice: 1680,
        marketLow: 1500,
        marketHigh: 1900,
        availability: "available",
        wholesaleOnly: true,
        imageUrl: "/media/lots/diamond.jpg",
        sku: "EG-MEL-240",
        notes: "Consistent make. Namibia this quarter. Trade only.",
      },
      {
        sellerId: claire.id,
        title: "Lightning ridge opal, 6.40 ct",
        gemType: "opal",
        origin: "Australia",
        weightCt: 6.4,
        color: "Black, rolling flash",
        treatment: "None",
        clarity: "N/A",
        certification: "Seller memo",
        cut: "Cabochon",
        dimensions: "16.2 × 12.1 × 5.4",
        askingPrice: 3100,
        marketLow: 2700,
        marketHigh: 3600,
        availability: "available",
        imageUrl: "/media/lots/opal.jpg",
        sku: "IB-OPL-640",
        notes: "No treatment. Strong play. Video in the room on request.",
      },
      {
        sellerId: claire.id,
        title: "Fantasy-cut tourmaline, 5.80 ct",
        gemType: "tourmaline",
        origin: "Nigeria",
        weightCt: 5.8,
        color: "Chrome green",
        treatment: "Heat",
        clarity: "VS",
        certification: "DSEF",
        cut: "Fantasy",
        dimensions: "14.0 × 9.2 × 6.0",
        askingPrice: 2700,
        marketLow: 2300,
        marketHigh: 3200,
        availability: "available",
        imageUrl: "/media/lots/tourmaline.jpg",
        sku: "IB-FAN-580",
        notes: "Idar fantasy cut. Heat disclosed. One-off for a jeweler, not a pair.",
      },
      {
        sellerId: admin.id,
        title: "Ceylon sapphire, 1.74 ct",
        gemType: "sapphire",
        origin: "Sri Lanka",
        weightCt: 1.74,
        color: "Light blue",
        treatment: "Heat",
        clarity: "Eye clean",
        certification: "GIA",
        cut: "Round",
        dimensions: "7.2 × 7.1 × 4.6",
        askingPrice: 1450,
        marketLow: 1200,
        marketHigh: 1800,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "EG-SAP-174",
        notes: "ElbeeGems floor stone. Heat disclosed. Clean round for a solitaire.",
      },
      {
        sellerId: admin.id,
        title: "Mozambique ruby, 0.88 ct",
        gemType: "ruby",
        origin: "Mozambique",
        weightCt: 0.88,
        color: "Medium red",
        treatment: "Heat",
        clarity: "VS",
        certification: "GIA",
        cut: "Oval",
        dimensions: "6.1 × 4.8 × 3.2",
        askingPrice: 920,
        marketLow: 800,
        marketHigh: 1150,
        availability: "sold",
        imageUrl: "/media/lots/ruby.jpg",
        sku: "EG-RBY-088",
        notes: "Left the tray last week. Kept on the floor as a comparable.",
      },
      {
        sellerId: ravi.id,
        title: "Spinel, 0.96 ct collector",
        gemType: "spinel",
        origin: "Tanzania",
        weightCt: 0.96,
        color: "Jedi blue",
        treatment: "None",
        clarity: "VVS",
        certification: "GRS",
        cut: "Cushion",
        dimensions: "5.8 × 5.4 × 3.7",
        askingPrice: 3600,
        marketLow: 3000,
        marketHigh: 4200,
        availability: "available",
        imageUrl: "/media/lots/spinel.jpg",
        sku: "PC-SPN-096",
        notes: "Small but neon. No treatment. Collector colour, not a calibrated size.",
      },
      {
        sellerId: kenji.id,
        title: "No-heat sapphire, 5.12 ct",
        gemType: "sapphire",
        origin: "Sri Lanka",
        weightCt: 5.12,
        color: "Medium blue",
        treatment: "Unheated",
        clarity: "SI",
        certification: "GIA",
        cut: "Oval",
        dimensions: "11.8 × 8.9 × 5.7",
        askingPrice: 15800,
        marketLow: 17000,
        marketHigh: 21000,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "KO-SAP-512",
        notes: "No heat, some silk. Priced below the usual band because of the window — recut candidate.",
      },
      {
        sellerId: hassan.id,
        title: "Umba sapphire, 2.40 ct",
        gemType: "sapphire",
        origin: "Tanzania",
        weightCt: 2.4,
        color: "Bi-colour teal",
        treatment: "Unheated",
        clarity: "VS",
        certification: "AIGS",
        cut: "Cushion",
        dimensions: "8.0 × 7.4 × 5.0",
        askingPrice: 1750,
        marketLow: 1500,
        marketHigh: 2200,
        availability: "available",
        imageUrl: "/media/lots/sapphire.jpg",
        sku: "RK-UMB-240",
        notes: "Mine note and crystal photo with the lot. No heat.",
      },
    ],
  });

  await prisma.follow.createMany({
    data: [
      { followerId: marcus.id, followingId: kenji.id },
      { followerId: sofia.id, followingId: aisha.id },
      { followerId: kenji.id, followingId: sofia.id },
      { followerId: lucia.id, followingId: ravi.id },
      { followerId: lucia.id, followingId: kenji.id },
      { followerId: elena.id, followingId: kenji.id },
      { followerId: elena.id, followingId: lab.id },
      { followerId: pierre.id, followingId: claire.id },
      { followerId: yuki.id, followingId: hassan.id },
      { followerId: diego.id, followingId: claire.id },
      { followerId: thomas.id, followingId: sofia.id },
      { followerId: jonas.id, followingId: lucia.id },
      { followerId: amara.id, followingId: pierre.id },
      { followerId: ravi.id, followingId: hassan.id },
      { followerId: noor.id, followingId: lab.id },
      { followerId: aisha.id, followingId: diego.id },
    ],
  });

  const now = Date.now();
  const days = (n: number) => new Date(now + n * 86_400_000);
  const hours = (n: number) => new Date(now + n * 3_600_000);

  await prisma.post.createMany({
    data: [
      {
        authorId: admin.id,
        kind: "announcement",
        title: "Weekly auction returns Thursday",
        body: "Medium-grade lots and one collector sapphire. Member bidding opens 18:00. Wholesale lots remain behind the trade door.",
        createdAt: hours(-20),
      },
      {
        authorId: kenji.id,
        kind: "update",
        title: "Taking recuts in September",
        body: "Two benches free after the 12th. Prefer corundum 3ct and up. Send origin notes with the rough.",
        createdAt: hours(-18),
      },
      {
        authorId: sofia.id,
        kind: "discussion",
        title: "Who is working Muzo material this quarter?",
        body: "Looking for a cutter who will hold the colour on a 4.2ct crystal. Not in a rush.",
        createdAt: hours(-16),
      },
      {
        authorId: admin.id,
        kind: "event",
        title: "Private viewing — Bangkok",
        body: "Invitation-only tray of certified sapphires. Verified professionals may request a seat.",
        eventAt: days(12),
        location: "Bangkok",
        createdAt: hours(-14),
      },
      {
        authorId: lucia.id,
        kind: "discussion",
        title: "Calibrated emerald pairs — who has 5x3?",
        body: "Need twenty pairs, consistent hue, minor oil acceptable. Jaipur delivery this month.",
        createdAt: hours(-12),
      },
      {
        authorId: ravi.id,
        kind: "update",
        title: "Padparadscha tray in from Ratnapura",
        body: "Eight stones, 1.2–2.8 ct. Papers on four. Verified dealers may request photos.",
        createdAt: hours(-10),
      },
      {
        authorId: hassan.id,
        kind: "update",
        title: "Mahenge parcel landed",
        body: "Spinel rough with crystal faces photographed. Prefer cutters who will keep the neon.",
        createdAt: hours(-9),
      },
      {
        authorId: lab.id,
        kind: "announcement",
        title: "72-hour origin reports this week",
        body: "North Gem Lab is clearing the queue for network members. Mark the memo “Elbee floor”.",
        createdAt: hours(-8),
      },
      {
        authorId: diego.id,
        kind: "discussion",
        title: "Tourmaline window after heat — opinions?",
        body: "A 6.1ct green is showing a window after a standard heat. Recut or leave for a pendant?",
        createdAt: hours(-7),
      },
      {
        authorId: elena.id,
        kind: "discussion",
        title: "Older GRS papers vs a new AIGS",
        body: "Would you re-paper a 1998 no-heat sapphire or leave the original envelope with the stone?",
        createdAt: hours(-6),
      },
      {
        authorId: claire.id,
        kind: "update",
        title: "Fantasy-cut commission slots",
        body: "Three benches in October. Tourmaline and beryl preferred. Send a sketch with the rough.",
        createdAt: hours(-5),
      },
      {
        authorId: pierre.id,
        kind: "discussion",
        title: "Melee consistency out of Namibia",
        body: "Anyone seeing better make on 1.3mm this quarter? Looking for a quiet parcel, not a story.",
        createdAt: hours(-4),
      },
      {
        authorId: yuki.id,
        kind: "update",
        title: "Looking for leftover calibrated spinel",
        body: "6x4 and 5x3. Mixed pinks acceptable if the saturation holds in LED.",
        createdAt: hours(-3),
      },
      {
        authorId: amara.id,
        kind: "discussion",
        title: "Garnet parcels for European workshops",
        body: "I can ship next week. Who is cutting rhodolite this season?",
        createdAt: hours(-2),
      },
      {
        authorId: noor.id,
        kind: "event",
        title: "Hong Kong lab day",
        body: "Fast-track origin reports for network members. Bring parcels with a memo.",
        eventAt: days(19),
        location: "Hong Kong",
        createdAt: hours(-30),
      },
      {
        authorId: kenji.id,
        kind: "event",
        title: "Cutter’s table — recuts",
        body: "Two corundum recuts walked on the bench. Limited to verified cutters and dealers.",
        eventAt: days(26),
        location: "Bangkok",
        createdAt: hours(-28),
      },
      {
        authorId: sofia.id,
        kind: "event",
        title: "Colombian emerald briefing",
        body: "Muzo and Chivor colour this quarter. Members may join from the floor.",
        eventAt: days(34),
        location: "Online",
        createdAt: hours(-26),
      },
      {
        authorId: admin.id,
        kind: "event",
        title: "Jaipur tray walk",
        body: "Verified jewelers only. Calibrated colour and one collector spinel.",
        eventAt: days(8),
        location: "Jaipur",
        createdAt: hours(-22),
      },
      {
        authorId: jonas.id,
        kind: "update",
        title: "New on the floor — melee source?",
        body: "Atelier in New York. Need a trusted melee house and a sapphire cutter who will talk on video.",
        createdAt: hours(-1),
      },
      {
        authorId: thomas.id,
        kind: "discussion",
        title: "First Ceylon under 3 ct — what to ask",
        body: "What should a new collector insist on besides a lab report? Heat, origin, and window?",
        createdAt: hours(-0.5),
      },
    ],
  });

  const byTitle = Object.fromEntries((await prisma.post.findMany()).map((post) => [post.title, post]));
  const reply = (title: string, authorId: string, body: string, createdAt: Date) => {
    const post = byTitle[title];
    if (!post) return null;
    return { postId: post.id, authorId, body, createdAt };
  };
  await prisma.reply.createMany({
    data: [
      reply(
        "First Ceylon under 3 ct — what to ask",
        kenji.id,
        "Ask for window photos in daylight and LED. A lab report without a window shot is only half the story under 3 ct.",
        hours(-0.4),
      ),
      reply(
        "First Ceylon under 3 ct — what to ask",
        elena.id,
        "I would also want clarity on heat. If they hesitate, walk. Plenty of clean Ceylon at this size.",
        hours(-0.2),
      ),
      reply(
        "Who is working Muzo material this quarter?",
        lucia.id,
        "I can take the crystal if you will send a face-up video. Colour first, yield second.",
        hours(-15),
      ),
      reply(
        "Who is working Muzo material this quarter?",
        kenji.id,
        "Not this month — recuts are full. Ping me in October if it is still open.",
        hours(-14),
      ),
      reply(
        "Calibrated emerald pairs — who has 5x3?",
        ravi.id,
        "I can do twelve pairs next week, oil minor. The rest would be 5.5x3.5 if you can flex.",
        hours(-11),
      ),
      reply(
        "Tourmaline window after heat — opinions?",
        claire.id,
        "Recut. A windowed green that size will never sit in a ring. Pendant only if the client already loves the crystal.",
        hours(-6.5),
      ),
      reply(
        "Looking for leftover calibrated spinel",
        hassan.id,
        "I have mixed pinks in 5x3 from the last parcel. Photos on request.",
        hours(-2.5),
      ),
      reply(
        "New on the floor — melee source?",
        pierre.id,
        "Namibia melee is consistent this quarter. I can jump on a video if you send a target size.",
        hours(-0.8),
      ),
      reply(
        "Garnet parcels for European workshops",
        diego.id,
        "I am cutting rhodolite through September. Send the parcel weight and a preferred make.",
        hours(-1.5),
      ),
      reply(
        "Weekly auction returns Thursday",
        marcus.id,
        "Will the collector sapphire carry papers? Helps to know before the clock starts.",
        hours(-19),
      ),
    ].filter((row): row is { postId: string; authorId: string; body: string; createdAt: Date } => Boolean(row)),
  });

  const auctions = await Promise.all(
    [
      {
        title: "Ceylon sapphire, 3.81 ct",
        category: "premium",
        description: "Unheated, AIGS report. Starting well under replacement.",
        origin: "Sri Lanka",
        certification: "AIGS",
        treatment: "None",
        imageUrl: "/media/lots/sapphire.jpg",
        startingBid: 2400,
        currentBid: 3100,
        minIncrement: 100,
        startsAt: hours(-6),
        endsAt: hours(36),
        status: "live",
        memberOnly: true,
      },
      {
        title: "Mixed tourmaline parcel",
        category: "medium",
        description: "Twelve stones, calibrated 6x4. Ideal for a jeweler's tray.",
        origin: "Nigeria",
        certification: "",
        treatment: "Standard heat",
        imageUrl: "/media/lots/tourmaline.jpg",
        startingBid: 380,
        currentBid: 520,
        minIncrement: 20,
        startsAt: hours(-8),
        endsAt: hours(8),
        status: "live",
        memberOnly: false,
      },
      {
        title: "Emerald melee lot — trade only",
        category: "wholesale",
        description: "48 ct total. Dealer-to-dealer. Trade-door lot only.",
        origin: "Colombia",
        certification: "Seller memo",
        treatment: "Minor oil",
        imageUrl: "/media/lots/emerald.jpg",
        startingBid: 1900,
        currentBid: 1900,
        minIncrement: 50,
        startsAt: hours(24),
        endsAt: days(5),
        status: "scheduled",
        wholesaleOnly: true,
      },
      {
        title: "Spinel, 2.04 ct collector",
        category: "collector",
        description: "Mahenge pink. No heat. For the cabinet, not the saw.",
        origin: "Tanzania",
        certification: "GRS",
        treatment: "None",
        imageUrl: "/media/lots/spinel.jpg",
        startingBid: 1600,
        currentBid: 1750,
        minIncrement: 75,
        startsAt: hours(48),
        endsAt: hours(72),
        status: "scheduled",
        memberOnly: true,
      },
      {
        title: "Mozambique ruby, 1.92 ct",
        category: "premium",
        description: "Heated, GRS. Strong fluorescence. Open to jewelers.",
        origin: "Mozambique",
        certification: "GRS",
        treatment: "Heat",
        imageUrl: "/media/lots/ruby.jpg",
        startingBid: 1800,
        currentBid: 2100,
        minIncrement: 80,
        startsAt: hours(-4),
        endsAt: hours(20),
        status: "live",
        memberOnly: true,
      },
      {
        title: "Lightning ridge opal, 6.4 ct",
        category: "collector",
        description: "Broad flash, no matrix. Cabinet stone.",
        origin: "Australia",
        certification: "Seller memo",
        treatment: "None",
        imageUrl: "/media/lots/opal.jpg",
        startingBid: 900,
        currentBid: 960,
        minIncrement: 40,
        startsAt: hours(-2),
        endsAt: hours(14),
        status: "live",
        memberOnly: false,
      },
      {
        title: "Rhodolite garnet parcel, 28 ct",
        category: "medium",
        description: "Mixed ovals, consistent hue. Workshop parcel.",
        origin: "Tanzania",
        certification: "",
        treatment: "None",
        imageUrl: "/media/lots/garnet.jpg",
        startingBid: 420,
        currentBid: 420,
        minIncrement: 25,
        startsAt: hours(12),
        endsAt: hours(60),
        status: "scheduled",
        memberOnly: false,
      },
      {
        title: "Old-cut diamond, 0.92 ct",
        category: "collector",
        description: "Cape tint, open culet. Not for recut.",
        origin: "Unknown",
        certification: "CGL",
        treatment: "None",
        imageUrl: "/media/lots/diamond.jpg",
        startingBid: 2200,
        currentBid: 2200,
        minIncrement: 100,
        startsAt: hours(30),
        endsAt: days(4),
        status: "scheduled",
        memberOnly: true,
      },
      {
        title: "South Sea pearl pair",
        category: "medium",
        description: "Matched pair, 11.2mm. For earrings.",
        origin: "Australia",
        certification: "Seller memo",
        treatment: "None",
        imageUrl: "/media/lots/pearl.jpg",
        startingBid: 1100,
        currentBid: 1250,
        minIncrement: 50,
        startsAt: hours(-10),
        endsAt: hours(-1),
        status: "closed",
        memberOnly: false,
      },
      {
        title: "Imperial jade cabochon, 8.1 ct",
        category: "premium",
        description: "Saturated green, minor texture. Not for recut.",
        origin: "Myanmar",
        certification: "Gübelin",
        treatment: "None",
        imageUrl: "/media/lots/jade.jpg",
        startingBid: 4800,
        currentBid: 5100,
        minIncrement: 150,
        startsAt: hours(-3),
        endsAt: hours(28),
        status: "live",
        memberOnly: true,
      },
      {
        title: "Aquamarine parcel — trade only",
        category: "wholesale",
        description: "62 ct Santa Maria colour. Invoice on request.",
        origin: "Brazil",
        certification: "Memo",
        treatment: "Heat",
        imageUrl: "/media/lots/jade.jpg",
        startingBid: 2400,
        currentBid: 2400,
        minIncrement: 75,
        startsAt: days(2),
        endsAt: days(6),
        status: "scheduled",
        wholesaleOnly: true,
      },
    ].map((lot) => prisma.auction.create({ data: lot })),
  );

  const [sapphire, tourmaline, , , ruby, opal, , , pearl, jade] = auctions;

  await prisma.bid.createMany({
    data: [
      { auctionId: sapphire.id, bidderId: elena.id, amount: 2500, createdAt: hours(-5) },
      { auctionId: sapphire.id, bidderId: marcus.id, amount: 2700, createdAt: hours(-4) },
      { auctionId: sapphire.id, bidderId: lucia.id, amount: 2900, createdAt: hours(-3) },
      { auctionId: sapphire.id, bidderId: elena.id, amount: 3100, createdAt: hours(-1) },
      { auctionId: tourmaline.id, bidderId: yuki.id, amount: 400, createdAt: hours(-7) },
      { auctionId: tourmaline.id, bidderId: jonas.id, amount: 440, createdAt: hours(-5) },
      { auctionId: tourmaline.id, bidderId: diego.id, amount: 480, createdAt: hours(-3) },
      { auctionId: tourmaline.id, bidderId: lucia.id, amount: 520, createdAt: hours(-1) },
      { auctionId: ruby.id, bidderId: pierre.id, amount: 1880, createdAt: hours(-3) },
      { auctionId: ruby.id, bidderId: ravi.id, amount: 1960, createdAt: hours(-2) },
      { auctionId: ruby.id, bidderId: lucia.id, amount: 2100, createdAt: hours(-1) },
      { auctionId: opal.id, bidderId: thomas.id, amount: 940, createdAt: hours(-1.5) },
      { auctionId: opal.id, bidderId: elena.id, amount: 960, createdAt: hours(-0.8) },
      { auctionId: pearl.id, bidderId: yuki.id, amount: 1150, createdAt: hours(-8) },
      { auctionId: pearl.id, bidderId: lucia.id, amount: 1250, createdAt: hours(-3) },
      { auctionId: jade.id, bidderId: ravi.id, amount: 4950, createdAt: hours(-2) },
      { auctionId: jade.id, bidderId: elena.id, amount: 5100, createdAt: hours(-0.6) },
    ],
  });

  await prisma.wholesaleLot.createMany({
    data: [
      {
        title: "Sapphire parcel — greens and teals",
        origin: "Madagascar",
        description: "84 ct. Mixed cuts. Invoice on request.",
        imageUrl: "/media/lots/sapphire.jpg",
        wholesalePrice: 4200,
        retailHint: 7800,
        quantity: 1,
        certificate: "Memo",
        treatment: "Heat",
        privateOffer: true,
      },
      {
        title: "Ruby calibrated 5x3",
        origin: "Mozambique",
        description: "Forty-eight stones. Consistent hue.",
        imageUrl: "/media/lots/ruby.jpg",
        wholesalePrice: 2600,
        quantity: 48,
        certificate: "",
        treatment: "Heat",
      },
      {
        title: "Emerald melee, 48 ct",
        origin: "Colombia",
        description: "Minor oil. Dealer-to-dealer only.",
        imageUrl: "/media/lots/emerald.jpg",
        wholesalePrice: 6100,
        quantity: 1,
        certificate: "Seller memo",
        treatment: "Minor oil",
        privateOffer: true,
      },
      {
        title: "Spinel calibrated 6x4",
        origin: "Tanzania",
        description: "Mahenge pinks. Twenty-four stones.",
        imageUrl: "/media/lots/spinel.jpg",
        wholesalePrice: 3400,
        quantity: 24,
        certificate: "Memo",
        treatment: "None",
      },
      {
        title: "Tourmaline tray, 36 ct",
        origin: "Brazil",
        description: "Greens and teals. Mixed ovals.",
        imageUrl: "/media/lots/tourmaline.jpg",
        wholesalePrice: 1800,
        quantity: 1,
        certificate: "",
        treatment: "None",
      },
      {
        title: "Garnet melee for workshops",
        origin: "Tanzania",
        description: "Rhodolite, 1.8–2.4mm. Two hundred stones.",
        imageUrl: "/media/lots/garnet.jpg",
        wholesalePrice: 920,
        quantity: 200,
        certificate: "",
        treatment: "None",
      },
    ],
  });

  async function room(
    status: string,
    gemTitle: string,
    a: { id: string },
    b: { id: string },
    messages: { sender: { id: string }; body: string; gemTitle?: string }[],
    offer?: { user: { id: string }; amount: number; status?: string },
  ) {
    const thread = await prisma.thread.create({
      data: {
        dealStatus: status,
        gemTitle,
        participants: { create: [{ userId: a.id }, { userId: b.id }] },
      },
    });
    await prisma.message.createMany({
      data: messages.map((message, index) => ({
        threadId: thread.id,
        senderId: message.sender.id,
        body: message.body,
        gemTitle: message.gemTitle,
        createdAt: hours(-messages.length + index),
      })),
    });
    if (offer) {
      await prisma.offer.create({
        data: { threadId: thread.id, userId: offer.user.id, amount: offer.amount, status: offer.status || "open" },
      });
    }
  }

  await room(
    "negotiating",
    "Ceylon sapphire recut",
    marcus,
    kenji,
    [
      { sender: marcus, body: "Kenji — I have a 5.1ct oval that needs a quieter pavilion. Can you look?", gemTitle: "Ceylon sapphire recut" },
      { sender: kenji, body: "Send the origin note and a video on the window. I can bench it the week of the 15th." },
      { sender: marcus, body: "Video is in the room. AIGS envelope is 2019. No heat." },
    ],
    { user: kenji, amount: 420 },
  );

  await room("open", "Muzo parcel, 12ct", sofia, aisha, [
    { sender: sofia, body: "Aisha — I can take the 12ct parcel if the origin notes are clean. Can you send photos of the crystal faces?", gemTitle: "Muzo parcel, 12ct" },
    { sender: aisha, body: "Notes are with the memo. I'll send the tray video tonight. Holding it until Friday." },
  ]);

  await room(
    "agreed",
    "Padparadscha 2.1 ct",
    lucia,
    ravi,
    [
      { sender: lucia, body: "Ravi, the 2.1ct pad is for a client ring. Can you hold colour in LED and daylight?", gemTitle: "Padparadscha 2.1 ct" },
      { sender: ravi, body: "Yes. Papers are GRS. I can invoice tomorrow if you confirm." },
      { sender: lucia, body: "Confirmed. Send the memo to Jaipur Atelier." },
    ],
    { user: ravi, amount: 3800, status: "accepted" },
  );

  await room("open", "Mahenge spinel rough", hassan, claire, [
    { sender: hassan, body: "Claire — three crystals, neon. I want them cut, not sold as rough.", gemTitle: "Mahenge spinel rough" },
    { sender: claire, body: "Send weights and a face video. October bench is possible." },
  ]);

  await room("negotiating", "Tourmaline 6.1 ct recut", diego, yuki, [
    { sender: yuki, body: "Diego, the window on the green — will you recut for a pendant or keep the weight?" },
    { sender: diego, body: "I would drop 0.4 ct and close the window. Better for your LED trays." },
  ]);

  await room("open", "Melee source", jonas, pierre, [
    { sender: jonas, body: "Pierre — I need 1.3mm melee, consistent make, quiet parcel. Can you quote?", gemTitle: "Diamond melee 1.3mm" },
    { sender: pierre, body: "I can. Namibia make this quarter is cleaner. I will put a memo in the room." },
  ]);

  await room("ordered", "Origin report, 3 stones", elena, noor, [
    { sender: elena, body: "Noor, three no-heat sapphires. Need origin and heat. Mark them Cabinet Bleu." },
    { sender: noor, body: "Received. 72-hour track. I will upload PDFs to the room." },
  ]);

  await prisma.wholesaleOrder.createMany({
    data: [
      { userId: sofia.id, title: "Sapphire parcel — greens and teals", amount: 4200, status: "pending" },
      { userId: ravi.id, title: "Ruby calibrated 5x3", amount: 2600, status: "invoiced" },
      { userId: claire.id, title: "Tourmaline tray, 36 ct", amount: 1800, status: "pending" },
    ],
  });

  await prisma.report.createMany({
    data: [
      { reporterId: elena.id, targetType: "post", targetId: "origin-discussion", reason: "Off-floor retail pitch in a trade thread." },
      { reporterId: kenji.id, targetType: "user", targetId: thomas.id, reason: "Asked for wholesale prices in a public discussion." },
    ],
  });

  console.log("Seeded ElbeeGems community.");
  console.log(`${created.length + 1} members, listings, lots, discussions, rooms, and wholesale desk.`);
  console.log("Admin: admin@elbeegems.com / ElbeeGems!dev");
  console.log("Wholesale demo: sofia@emeraldcoast.example / ElbeeGems!dev");
  console.log("Cutter demo: kenji@facetstudio.example / ElbeeGems!dev");
}

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