import { connectDatabase } from "../config/db.js";
import { User } from "../models/User.js";
import { Vendor } from "../models/Vendor.js";
import { Product } from "../models/Product.js";
import { Campaign } from "../models/Campaign.js";

await connectDatabase();

await Promise.all([
  User.deleteMany({}),
  Vendor.deleteMany({}),
  Product.deleteMany({}),
  Campaign.deleteMany({})
]);

const admin = await User.create({
  fullName: "OMOSALA Super Admin",
  email: "admin@omosalaprints.ng",
  password: "Password123!",
  role: "super_admin",
  isVerified: true
});

const seller = await User.create({
  fullName: "OMOSALA Print Manager",
  email: "seller@omosalaprints.ng",
  password: "Password123!",
  role: "seller",
  isVerified: true
});

const vendor = await Vendor.create({
  owner: seller._id,
  storeName: "OMOSALA PRINT Studio",
  slug: "omosala-print-studio",
  category: "Print & Branding",
  kycStatus: "approved",
  rating: 4.9,
  totalOrders: 48000
});

await Product.insertMany([
  {
    vendor: vendor._id,
    name: "Premium Business Cards - Matte Finish",
    slug: "premium-business-cards-matte",
    category: "Printing Services",
    price: 18500,
    oldPrice: 24000,
    stock: 420,
    sku: "OMS-BC-MATTE-001",
    status: "approved",
    tags: ["business cards", "custom print", "branding"]
  },
  {
    vendor: vendor._id,
    name: "A5 Flyers - Full Color",
    slug: "a5-flyers-full-color",
    category: "Printing Services",
    price: 42000,
    oldPrice: 51000,
    stock: 5000,
    sku: "OMS-FLY-A5-001",
    status: "approved",
    tags: ["flyers", "marketing", "campaign"]
  }
]);

await Campaign.create({
  name: "OMOSALA Business Growth Flash Sale",
  type: "flash_sale",
  startsAt: new Date(),
  endsAt: new Date(Date.now() + 72 * 60 * 60 * 1000),
  discountPercent: 45,
  status: "active",
  audience: ["customers", "vendors", "print_buyers"]
});

console.log("Seed complete");
console.log("Admin:", admin.email, "Password123!");
process.exit(0);
