import mongoose from "mongoose";

const ZoomMeetingSchema = new mongoose.Schema(
  {
    // Zoom API fields
    zoomMeetingId: { type: String, required: true, unique: true, trim: true },
    topic: { type: String, required: true, trim: true },
    startTime: { type: Date, required: true },
    duration: { type: Number, required: true, default: 30 }, // in minutes
    timezone: { type: String, default: "Asia/Karachi" },
    joinUrl: { type: String, required: true },
    startUrl: { type: String, required: true }, // Host URL
    meetingNumber: { type: String, trim: true },
    password: { type: String, trim: true },
    
    // User/Client information
    fullName: { type: String, required: true, trim: true },
    email: { type: String, required: true, trim: true, lowercase: true },
    meetingType: { type: String, trim: true },
    preferredMeetingTime: { type: String, trim: true },
    projectDescription: { type: String, trim: true },
    additionalNotes: { type: String, trim: true },
    
    // Attendees
    attendees: [{
      name: { type: String, trim: true },
      email: { type: String, trim: true, lowercase: true },
    }],
    
    // Status tracking
    status: {
      type: String,
      enum: ["Scheduled", "Completed", "Cancelled", "In Progress"],
      default: "Scheduled",
    },
    
    // Host information
    hostUserId: { type: String, trim: true },
  },
  { timestamps: true }
);

ZoomMeetingSchema.index({ startTime: -1 });
ZoomMeetingSchema.index({ email: 1 });
ZoomMeetingSchema.index({ status: 1 });
ZoomMeetingSchema.index({ zoomMeetingId: 1 });

const ZoomMeetingModel = mongoose.models.ZoomMeeting || mongoose.model("ZoomMeeting", ZoomMeetingSchema);

export { ZoomMeetingModel };

