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: [

"story",


"acceptance_criteria",


"quality_check",


"rewrite"

        ],

      },

input_text: {
        type: DataTypes.TEXT,
      
      

      },

output_json: {
        type: DataTypes.TEXT,
      
      

      },

estimated_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

      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.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

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

    db.ai_generations.belongsTo(db.user_stories, {
      as: 'story',
      foreignKey: {
        name: 'storyId',
      },
      constraints: false,
    });

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




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

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



  return ai_generations;
};


