const mongoose = require("mongoose");

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