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

generation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"meal_plan",


"training_program",


"blood_test_interpretation",


"supplement_recommendation",


"supplement_interaction_check",


"drug_interaction_check",


"correlation_insight",


"daily_insight",


"pre_appointment_checklist",


"symptom_checker",


"recipe_import"

        ],

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

prompt_context_json: {
        type: DataTypes.TEXT,
      
      

      },

result_json: {
        type: DataTypes.TEXT,
      
      

      },

status_message: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return ai_generations;
};


