import mongoose from "mongoose";

const bookingSchema = new mongoose.Schema(
  {
    studentId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },

    teacherId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Teacher",
      required: true,
    },

    date: {
      type: Date,
      required: true,
    },

    time: {
      type: String,
      required: true,
    },

    duration: {
      type: Number,
      required: true,
      min: 1,
    },

    status: {
      type: String,
      enum: ["pending", "confirmed", "completed", "cancelled"],
      default: "pending",
    },

    zoomMeetingId: {
      type: String,
      default: "",
    },

    zoomJoinUrl: {
      type: String,
      default: "",
    },

    zoomStartUrl: {
      type: String,
      default: "",
    },

    recordingUrl: {
      type: String,
      default: "",
    },

stripeSessionId: {
  type: String,
  unique: true,
  sparse: true,
},
  },
  { timestamps: true }
);

// ✅🔥 PREVENT DUPLICATE BOOKINGS
bookingSchema.index(
  { teacherId: 1, date: 1, time: 1 },
  { unique: true }
);

export const Booking = mongoose.model("Booking", bookingSchema);