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

directive_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"living_will",


"dnr",


"healthcare_proxy",


"power_of_attorney",


"other"

        ],

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

proxy_contact_details: {
        type: DataTypes.TEXT,
      
      

      },

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

  advance_directives.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.advance_directives.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



    db.advance_directives.hasMany(db.file, {
      as: 'document_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.advance_directives.getTableName(),
        belongsToColumn: 'document_files',
      },
    });


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

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



  return advance_directives;
};


