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

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

categorySchema.plugin(toJSON)
categorySchema.plugin(paginate)

const Category = model<ICategory, ICategoryModel>('Category', categorySchema)
export default Category
