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

run_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"generate",


"analyze",


"teardown",


"compliance_review",


"ab_test_plan",


"research_summary"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

run_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

input_prompt: {
        type: DataTypes.TEXT,
      
      

      },

model_label: {
        type: DataTypes.TEXT,
      
      

      },

temperature: {
        type: DataTypes.DECIMAL,
      
      

      },

retrieved_chunk_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

  generation_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.generation_runs.hasMany(db.generation_outputs, {
      as: 'generation_outputs_generation_run',
      foreignKey: {
          name: 'generation_runId',
      },
      constraints: false,
    });










//end loop



    db.generation_runs.belongsTo(db.ad_projects, {
      as: 'ad_project',
      foreignKey: {
        name: 'ad_projectId',
      },
      constraints: false,
    });

    db.generation_runs.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });




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

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



  return generation_runs;
};


