import mongoose from 'mongoose';
import { generateId } from '../../utils.js';
const { Schema } = mongoose;

const noteTypeSchema = new Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: {
      type: String,
      required: true,
      unique: true,
    },
    color: {
      type: String,
      required: false,
    },
    active: {
      type: Boolean,
      required: true,
      default: true,
    },
  },
  { timestamps: true }
);

// Add virtual id getter
noteTypeSchema.virtual('id').get(function () {
  return this._id;
});

// Configure JSON serialization to include virtuals
noteTypeSchema.set('toJSON', { virtuals: true });

export const noteTypeModel = mongoose.model('noteType', noteTypeSchema);
