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

session_name: {
        type: DataTypes.TEXT,
      
      

      },

started: {
        type: DataTypes.DATE,
      
      

      },

ended: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"processing",


"completed",


"failed"

        ],

      },

response_cache: {
        type: DataTypes.TEXT,
      
      

      },

progress_percent: {
        type: DataTypes.INTEGER,
      
      

      },

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

  fill_sessions.associate = (db) => {


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










    db.fill_sessions.hasMany(db.request_queue, {
      as: 'request_queue_session',
      foreignKey: {
          name: 'sessionId',
      },
      constraints: false,
    });






//end loop



    db.fill_sessions.belongsTo(db.surveys, {
      as: 'survey',
      foreignKey: {
        name: 'surveyId',
      },
      constraints: false,
    });

    db.fill_sessions.belongsTo(db.ai_models, {
      as: 'ai_model',
      foreignKey: {
        name: 'ai_modelId',
      },
      constraints: false,
    });

    db.fill_sessions.belongsTo(db.api_keys, {
      as: 'api_key',
      foreignKey: {
        name: 'api_keyId',
      },
      constraints: false,
    });




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

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



  return fill_sessions;
};


