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

layer_name: {
        type: DataTypes.TEXT,
      
      

      },

priority_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

influence_weight: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  campaign_brain_configs.associate = (db) => {

    db.campaign_brain_configs.belongsToMany(db.skill_modules, {
      as: 'enabled_skill_modules',
      foreignKey: {
        name: 'campaign_brain_configs_enabled_skill_modulesId',
      },
      constraints: false,
      through: 'campaign_brain_configsEnabled_skill_modulesSkill_modules',
    });

    db.campaign_brain_configs.belongsToMany(db.skill_modules, {
      as: 'enabled_skill_modules_filter',
      foreignKey: {
        name: 'campaign_brain_configs_enabled_skill_modulesId',
      },
      constraints: false,
      through: 'campaign_brain_configsEnabled_skill_modulesSkill_modules',
    });


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity


























    db.campaign_brain_configs.hasMany(db.sandbox_scenarios, {
      as: 'sandbox_scenarios_campaign_brain_config',
      foreignKey: {
          name: 'campaign_brain_configId',
      },
      constraints: false,
    });





//end loop



    db.campaign_brain_configs.belongsTo(db.campaigns, {
      as: 'campaign',
      foreignKey: {
        name: 'campaignId',
      },
      constraints: false,
    });

    db.campaign_brain_configs.belongsTo(db.brain_profiles, {
      as: 'brain_profile',
      foreignKey: {
        name: 'brain_profileId',
      },
      constraints: false,
    });




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

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



  return campaign_brain_configs;
};


