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

role_in_family: {
        type: DataTypes.ENUM,
      
      

        values: [

"parent",


"child",


"grandparent",


"sibling",


"guardian",


"relative"

        ],

      },

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

      },

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

  family_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.family_memberships.belongsTo(db.families, {
      as: 'family',
      foreignKey: {
        name: 'familyId',
      },
      constraints: false,
    });

    db.family_memberships.belongsTo(db.npcs, {
      as: 'npc',
      foreignKey: {
        name: 'npcId',
      },
      constraints: false,
    });




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

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



  return family_memberships;
};


