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

field_key: {
        type: DataTypes.TEXT,
      
      

      },

label: {
        type: DataTypes.TEXT,
      
      

      },

value_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"number",


"date",


"boolean",


"party",


"citation",


"custom"

        ],

      },

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

      },

default_value: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

help_text: {
        type: DataTypes.TEXT,
      
      

      },

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

  template_fields.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.template_fields.belongsTo(db.legal_templates, {
      as: 'template',
      foreignKey: {
        name: 'templateId',
      },
      constraints: false,
    });




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

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



  return template_fields;
};


