import { Schema, model } from 'mongoose'
import { paginate, toJSON } from '@/shared/utils/plugins/index.js'
import { IPropertySize, IPropertySizeModel } from '../property.interfaces'

const propertySizeSchema = new Schema<IPropertySize>(
  {
    name: { type: String, required: true, trim: true, lowercase: true },
    sqFeetUnit: { type: Number, required: true },
    createdBy: { type: Schema.Types.ObjectId, ref: 'User' },
    updatedBy: { type: Schema.Types.ObjectId, ref: 'User' },
  },
  { timestamps: true },
)

propertySizeSchema.index({ name: 1 }, { unique: true })

propertySizeSchema.plugin(toJSON)
propertySizeSchema.plugin(paginate)

const PropertySize = model<IPropertySize, IPropertySizeModel>('PropertySize', propertySizeSchema)
export default PropertySize
