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

name: {
        type: DataTypes.TEXT,
      
      

      },

key: {
        type: DataTypes.TEXT,
      
      

      },

value_text: {
        type: DataTypes.TEXT,
      
      

      },

value_number: {
        type: DataTypes.DECIMAL,
      
      

      },

value_datetime: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  contract_data_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.contract_data_fields.belongsTo(db.contract_documents, {
      as: 'contract_document',
      foreignKey: {
        name: 'contract_documentId',
      },
      constraints: false,
    });

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




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

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



  return contract_data_fields;
};


