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

turn_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"opening",


"direct_exam",


"cross_exam",


"argument",


"ruling",


"objection",


"sidebar",


"closing",


"general"

        ],

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

spoken_at: {
        type: DataTypes.DATE,
      
      

      },

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

  mock_trial_turns.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.mock_trial_turns.belongsTo(db.mock_trials, {
      as: 'mock_trial',
      foreignKey: {
        name: 'mock_trialId',
      },
      constraints: false,
    });

    db.mock_trial_turns.belongsTo(db.mock_trial_roles, {
      as: 'role',
      foreignKey: {
        name: 'roleId',
      },
      constraints: false,
    });

    db.mock_trial_turns.belongsTo(db.files, {
      as: 'audio_file',
      foreignKey: {
        name: 'audio_fileId',
      },
      constraints: false,
    });




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

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



  return mock_trial_turns;
};


