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

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"room_members",


"moderators_only"

        ],

      },

added_at: {
        type: DataTypes.DATE,
      
      

      },

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

  room_files.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.room_files.belongsTo(db.rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });

    db.room_files.belongsTo(db.files, {
      as: 'file',
      foreignKey: {
        name: 'fileId',
      },
      constraints: false,
    });

    db.room_files.belongsTo(db.users, {
      as: 'added_by',
      foreignKey: {
        name: 'added_byId',
      },
      constraints: false,
    });

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




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

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



  return room_files;
};


