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

test_category: {
        type: DataTypes.ENUM,
      
      

        values: [

"comminution",


"gravity",


"flotation",


"leaching",


"thickening",


"filtration",


"rheology",


"environmental",


"mineralogy",


"assay"

        ],

      },

test_type: {
        type: DataTypes.TEXT,
      
      

      },

display_name_en: {
        type: DataTypes.TEXT,
      
      

      },

display_name_fr: {
        type: DataTypes.TEXT,
      
      

      },

parameters_schema_json: {
        type: DataTypes.TEXT,
      
      

      },

results_schema_json: {
        type: DataTypes.TEXT,
      
      

      },

calculation_rules_json: {
        type: DataTypes.TEXT,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  test_type_schemas.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_type_schemas.hasMany(db.metallurgical_tests, {
      as: 'metallurgical_tests_test_type_schema',
      foreignKey: {
          name: 'test_type_schemaId',
      },
      constraints: false,
    });





















//end loop



    db.test_type_schemas.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return test_type_schemas;
};


