const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const document_versions = sequelize.define(
    'document_versions',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

version_number: {
        type: DataTypes.INTEGER,
      
      

      },

content_markdown: {
        type: DataTypes.TEXT,
      
      

      },

saved_at: {
        type: DataTypes.DATE,
      
      

      },

change_summary: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  document_versions.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity































//end loop



    db.document_versions.belongsTo(db.documents, {
      as: 'document',
      foreignKey: {
        name: 'documentId',
      },
      constraints: false,
    });

    db.document_versions.belongsTo(db.users, {
      as: 'editor',
      foreignKey: {
        name: 'editorId',
      },
      constraints: false,
    });

    db.document_versions.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.document_versions.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.document_versions.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return document_versions;
};


