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

source: {
        type: DataTypes.ENUM,
      
      

        values: [

"github",


"reddit",


"other_ai_platform"

        ],

      },

signal_type: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

source_url: {
        type: DataTypes.TEXT,
      
      

      },

signal_score: {
        type: DataTypes.DECIMAL,
      
      

      },

signal_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  external_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.external_signals.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return external_signals;
};


