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

title: {
        type: DataTypes.TEXT,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

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

  test_matrices.associate = (db) => {


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
























    db.test_matrices.hasMany(db.matrix_rows, {
      as: 'matrix_rows_test_matrix',
      foreignKey: {
          name: 'test_matrixId',
      },
      constraints: false,
    });





//end loop



    db.test_matrices.belongsTo(db.test_versions, {
      as: 'test_version',
      foreignKey: {
        name: 'test_versionId',
      },
      constraints: false,
    });



    db.test_matrices.hasMany(db.file, {
      as: 'export_pdf',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.test_matrices.getTableName(),
        belongsToColumn: 'export_pdf',
      },
    });

    db.test_matrices.hasMany(db.file, {
      as: 'export_docx',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.test_matrices.getTableName(),
        belongsToColumn: 'export_docx',
      },
    });


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

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



  return test_matrices;
};


