const ObjectId = require('bson').ObjectID;

class History {
  constructor(user, action, collection, documentId, payload, inventoryId = null) {
    this.action = action;
    this.modifiedDate = new Date();
    this.modifiedBy = {
      userId: user.userId,
      firstName: user.firstName,
      lastName: user.lastName,
    };
    this.collection = collection;
    this.payload = payload;
    let tempDocId = null;
    try {
      tempDocId = typeof documentId === 'string' ? new ObjectId(documentId) : documentId;
    } catch (e) {
      tempDocId = documentId;
    }
    this.documentId = tempDocId;
    this.inventoryId = inventoryId;
  }
}

module.exports = History;
