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

signal_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"metric_import",


"ab_result",


"audience_comment",


"competitor_change",


"seasonal_pattern",


"manual_insight"

        ],

      },

signal_at: {
        type: DataTypes.DATE,
      
      

      },

signal_title: {
        type: DataTypes.TEXT,
      
      

      },

signal_details: {
        type: DataTypes.TEXT,
      
      

      },

confidence_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  learning_signals.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.learning_signals.belongsTo(db.campaigns, {
      as: 'campaign',
      foreignKey: {
        name: 'campaignId',
      },
      constraints: false,
    });




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

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



  return learning_signals;
};


