// models/slotModel.js
const mongoose = require("mongoose");


const slotItemSchema = new mongoose.Schema(
  {
    startTime: { type: String, required: true }, // "09:30"
    endTime: { type: String, required: true },   // "10:00"

    isBooked: { type: Boolean, default: false },

    bookedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      default: null,
    },
  },
  { _id: false }
);


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

    // date: {
    //   type: String, // YYYY-MM-DD
    //   required: true,
    // },

    duration: {
      type: Number,
      required: true,
    },
    slots: [slotItemSchema],
    orgId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Organization",
      required: true,
    },
    createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
    
    isDeleted: {
      type: Boolean,
      default: false, // soft delete flag
    },
  },
  { timestamps: true }
);

module.exports = mongoose.model("Slot", slotSchema);
