const mongoose = require('mongoose');

const librarySchema = new mongoose.Schema(
  {
    companyId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Company',
      required: true
    },
    title: {
      type: String,
      required: [true, 'Title is required'],
      trim: true
    },
    description: {
      type: String,
      trim: true
    },
    category: {
      type: String,
      required: true,
      trim: true
    },
    tags: [
      {
        type: String,
        trim: true
      }
    ],
    file: {
      originalName: {
        type: String,
        required: true
      },
      fileName: {
        type: String,
        required: true
      },
      url: {
        type: String,
        required: true
      },
      mimeType: String,
      size: {
        type: Number,
        required: true
      },
      extension: String,
      documentType: {
        type: String,
        enum: ['image', 'video', 'audio', 'document', 'spreadsheet', 'presentation', 'archive', 'other'],
        default: 'other'
      }
    },
    status: {
      type: String,
      enum: ['active', 'archived', 'deleted'],
      default: 'active'
    },
    createdBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User',
      required: true
    },
    updatedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User'
    }
  },
  {
    timestamps: true
  }
);

module.exports = mongoose.model('Library', librarySchema);