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

data_category: {
        type: DataTypes.ENUM,
      
      

        values: [

"profile",


"fitness",


"nutrition",


"sleep",


"mood",


"medical_metrics",


"symptoms",


"medications",


"location"

        ],

      },

access_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"no_access",


"view_only",


"can_add_edit"

        ],

      },

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

  sharing_permissions.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.sharing_permissions.belongsTo(db.family_groups, {
      as: 'family_group',
      foreignKey: {
        name: 'family_groupId',
      },
      constraints: false,
    });

    db.sharing_permissions.belongsTo(db.users, {
      as: 'granter_user',
      foreignKey: {
        name: 'granter_userId',
      },
      constraints: false,
    });

    db.sharing_permissions.belongsTo(db.users, {
      as: 'grantee_user',
      foreignKey: {
        name: 'grantee_userId',
      },
      constraints: false,
    });




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

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



  return sharing_permissions;
};


