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

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"pattern",


"weakness",


"edge",


"tip",


"alert",


"sizing",


"market_condition",


"summary"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"info",


"low",


"medium",


"high"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

detail: {
        type: DataTypes.TEXT,
      
      

      },

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

  ai_insight_items.associate = (db) => {

    db.ai_insight_items.belongsToMany(db.trades, {
      as: 'related_trades',
      foreignKey: {
        name: 'ai_insight_items_related_tradesId',
      },
      constraints: false,
      through: 'ai_insight_itemsRelated_tradesTrades',
    });

    db.ai_insight_items.belongsToMany(db.trades, {
      as: 'related_trades_filter',
      foreignKey: {
        name: 'ai_insight_items_related_tradesId',
      },
      constraints: false,
      through: 'ai_insight_itemsRelated_tradesTrades',
    });


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































//end loop



    db.ai_insight_items.belongsTo(db.ai_insight_runs, {
      as: 'ai_insight_run',
      foreignKey: {
        name: 'ai_insight_runId',
      },
      constraints: false,
    });




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

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



  return ai_insight_items;
};


