const mongoose = require('mongoose');
const timestamp = require('mongoose-timestamp');
const mongoosePaginate = require('mongoose-paginate-v2');

const modelSchema = new mongoose.Schema({
  post_images: {
    type: [String], // آرایه‌ای از مسیرهای تصاویر
    required: false,
    default: [],
  },
  post_video: {
    type: String, // مسیر ویدئو
    required: false,
    trim: true,
    default: null,
  },
  type: {
    type: String, // نوع پست: 'image' یا 'video'
    required: true,
    enum: ['image', 'video'],
  },
  files: [
    {
      path: { type: String, required: true },
      type: { type: String, enum: ['image', 'video'], required: true },
    }
  ],
  caption: {
    type: String,
    required: false,
    trim: true,
    minLength: 1,
    maxLength: 1000,
    default: null,
  },
  status: {
    type: String,
    required: false,
    trim: true,
    enum: ['pending', 'accept', 'reject'],
    default: 'pending',
  },
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
  },
  likes: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
  }],
  comments: {
    type: Object,
    default: null,
  },
});

modelSchema.plugin(timestamp);
modelSchema.plugin(mongoosePaginate);
const PostModel = mongoose.model('Post', modelSchema);
module.exports = PostModel;