const mongoose = require("mongoose");

const designationSchema = new mongoose.Schema(
  {
    designationName: {
      type: String,
      required: [true, "Designation name is required"],
      trim: true,
      minlength: [3, "Designation name must be at least 3 characters long"],
      maxlength: [150, "Designation name cannot exceed 150 characters"],
    },
    departmentId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Department",
      required: [true, "Department ID is required"],
    },
    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,
    },
  }
);

module.exports = mongoose.model("Designation", designationSchema);
