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

const fileSchema = new Schema<IFileDoc>(
  {
    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,
    },
    project: {
      type: Schema.Types.ObjectId,
      ref: 'Project',
      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,
  },
);

fileSchema.plugin(toJSON);
fileSchema.plugin(paginate);

const File = model<IFileDoc, IFileModel>('File', fileSchema);

export default File;
export { File };