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

session_title: {
        type: DataTypes.TEXT,
      
      

      },

mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"scripted",


"realtime"

        ],

      },

input_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"voice",


"mixed"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"in_progress",


"completed",


"archived"

        ],

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

scenario_brief: {
        type: DataTypes.TEXT,
      
      

      },

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

  mock_trials.associate = (db) => {


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























    db.mock_trials.hasMany(db.mock_trial_roles, {
      as: 'mock_trial_roles_mock_trial',
      foreignKey: {
          name: 'mock_trialId',
      },
      constraints: false,
    });


    db.mock_trials.hasMany(db.mock_trial_turns, {
      as: 'mock_trial_turns_mock_trial',
      foreignKey: {
          name: 'mock_trialId',
      },
      constraints: false,
    });








//end loop



    db.mock_trials.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });

    db.mock_trials.belongsTo(db.matters, {
      as: 'matter',
      foreignKey: {
        name: 'matterId',
      },
      constraints: false,
    });




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

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



  return mock_trials;
};


