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

source_column: {
        type: DataTypes.TEXT,
      
      

      },

target_field: {
        type: DataTypes.TEXT,
      
      

      },

transform_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"none",


"trim",


"uppercase",


"lowercase",


"replace",


"concat",


"date_parse",


"number_parse",


"lookup"

        ],

      },

transform_config: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

order_index: {
        type: DataTypes.INTEGER,
      
      

      },

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

  mapping_rules.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.mapping_rules.belongsTo(db.import_mappings, {
      as: 'mapping',
      foreignKey: {
        name: 'mappingId',
      },
      constraints: false,
    });

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




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

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



  return mapping_rules;
};


