import { Schema, model } from 'mongoose';
import { toJSON, paginate } from '@/shared/utils/plugins';
import { Status } from '@/shared/constants/enum.constant';
import { IPropertyFileDoc, IPropertyFileModel } from './files.interface';

const propertyFileSchema = new Schema<IPropertyFileDoc>(
  {
    name: {
      type: String,
      required: true,
      trim: true,
    },
    category: {
      type: String,
      required: true,
      trim: true,
    },
    description: {
      type: String,
      trim: true,
      default: '',
    },
    fileUrl: {
      type: String,
      required: true,
    },
    fileType: {
      type: String,
      required: true,
    },
    size: {
      type: String,
      required: true,
    },
    propertyId: {
      type: Schema.Types.ObjectId,
      ref: 'IndividualProperty',
      required: true,
    },
    status: {
      type: String,
      enum: Object.values(Status),
      default: Status.ACTIVE,
    },
    createdBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
      required: true,
    },
    updatedBy: {
      type: Schema.Types.ObjectId,
      ref: 'User',
    },
  },
  {
    timestamps: true,
  },
);

propertyFileSchema.plugin(toJSON);
propertyFileSchema.plugin(paginate);

const PropertyFile = model<IPropertyFileDoc, IPropertyFileModel>(
  'PropertyFile',
  propertyFileSchema,
);

export default PropertyFile;
export { PropertyFile };
