import mongoose from "mongoose";

// Each flavour item schema
const FlavourSchema = new mongoose.Schema({
  flavour: { type: String, required: true },
  pieces: { type: Number, required: true },
  unitPrice: { type: Number, required: true },
  totalPrice: { type: Number, required: true },
});

// Main Cake Order schema
const CakeOrderSchema = new mongoose.Schema(
  {
    name: { type: String, required: true }, // ✅ New field
    phone: { type: String, required: true }, // ✅ New field
    cemail: { type: String, required: true }, // ✅ New field
    email: { type: String, required: true }, // ✅ Already existed, keep required
    order: {
      type: Map,
      of: [FlavourSchema], // Each category has an array of flavour objects
      required: true,
    },
    totalPieces: { type: Number, required: true },
    totalPrice: { type: Number, required: true },
    hst: { type: Number, default: 0 }, // HST
  },
  { timestamps: true }
);

export const CakeOrder = mongoose.model("CakeOrder", CakeOrderSchema);
