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

const documentSizeSchema = new Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: {
      type: String,
      required: true,
      unique: true,
    },
    width: {
      type: Number,
      required: true,
      default: 0,
    },
    height: {
      type: Number,
      required: true,
      default: 0,
    },
    infiniteHeight: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  { timestamps: true }
);

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

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

export const documentSizeModel = mongoose.model('documentSize', documentSizeSchema);
