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

name: {
        type: DataTypes.TEXT,
      
      

      },

key: {
        type: DataTypes.TEXT,
      
      

      },

data_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"string",


"number",


"date",


"datetime",


"boolean",


"currency",


"person",


"address"

        ],

      },

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

      },

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

      },

help_text: {
        type: DataTypes.TEXT,
      
      

      },

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

  document_template_variables.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.document_template_variables.belongsTo(db.document_types, {
      as: 'document_type',
      foreignKey: {
        name: 'document_typeId',
      },
      constraints: false,
    });

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




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

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



  return document_template_variables;
};


