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

run_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"daily_summary",


"weekly_summary",


"trade_review",


"pattern_scan",


"risk_sizing",


"market_condition"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

period_start_at: {
        type: DataTypes.DATE,
      
      

      },

period_end_at: {
        type: DataTypes.DATE,
      
      

      },

prompt_snapshot: {
        type: DataTypes.TEXT,
      
      

      },

output_summary: {
        type: DataTypes.TEXT,
      
      

      },

consistency_score: {
        type: DataTypes.DECIMAL,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ai_insight_runs.associate = (db) => {


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

























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







//end loop



    db.ai_insight_runs.belongsTo(db.trading_accounts, {
      as: 'trading_account',
      foreignKey: {
        name: 'trading_accountId',
      },
      constraints: false,
    });




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

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



  return ai_insight_runs;
};


