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

role: {
        type: DataTypes.ENUM,
      
      

        values: [

"owner",


"admin",


"editor",


"viewer"

        ],

      },

joined_at: {
        type: DataTypes.DATE,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  workspace_memberships.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.workspace_memberships.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.workspace_memberships.belongsTo(db.users, {
      as: 'member_user',
      foreignKey: {
        name: 'member_userId',
      },
      constraints: false,
    });

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




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

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



  return workspace_memberships;
};


