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_folders = sequelize.define(
    'document_folders',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  document_folders.associate = (db) => {


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











    db.document_folders.hasMany(db.documents, {
      as: 'documents_folder',
      foreignKey: {
          name: 'folderId',
      },
      constraints: false,
    });





















//end loop



    db.document_folders.belongsTo(db.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

    db.document_folders.belongsTo(db.document_folders, {
      as: 'parent',
      foreignKey: {
        name: 'parentId',
      },
      constraints: false,
    });

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




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

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



  return document_folders;
};


