const mongoose = require("mongoose");

const departmentSchema = new mongoose.Schema(
  {
    deptName: {
      type: String,
      required: [true, "Department name is required"],
      trim: true,
    },
    orgId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Organization",
      required: [true, "Organization ID is required"],
    },
    status: {
      type: Boolean,
      default: true, // active by default
    },
    isDeleted: {
      type: Boolean,
      default: false, // soft delete flag
    },
    createdBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },
    updatedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      // required: true,
      default: null
    },
    updatedAt: {
      type: Date,
      default: null, //  IMPORTANT
    },
  },
  {
    timestamps: {
      createdAt: true,
      updatedAt: false, //  THIS IS THE KEY LINE
    },
  }
);

module.exports = mongoose.model("Department", departmentSchema);
