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

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"call",


"chat",


"email",


"in_person"

        ],

      },

interaction_reference: {
        type: DataTypes.TEXT,
      
      

      },

interaction_at: {
        type: DataTypes.DATE,
      
      

      },

evaluated_at: {
        type: DataTypes.DATE,
      
      

      },

overall_score: {
        type: DataTypes.DECIMAL,
      
      

      },

result: {
        type: DataTypes.ENUM,
      
      

        values: [

"pass",


"needs_improvement",


"fail"

        ],

      },

summary_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  qa_evaluations.associate = (db) => {


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







































    db.qa_evaluations.hasMany(db.qa_scorecards, {
      as: 'qa_scorecards_qa_evaluation',
      foreignKey: {
          name: 'qa_evaluationId',
      },
      constraints: false,
    });









//end loop



    db.qa_evaluations.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.qa_evaluations.belongsTo(db.users, {
      as: 'evaluator',
      foreignKey: {
        name: 'evaluatorId',
      },
      constraints: false,
    });

    db.qa_evaluations.belongsTo(db.users, {
      as: 'agent',
      foreignKey: {
        name: 'agentId',
      },
      constraints: false,
    });




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

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



  return qa_evaluations;
};


