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

measured_at: {
        type: DataTypes.DATE,
      
      

      },

parameter_name: {
        type: DataTypes.TEXT,
      
      

      },

value: {
        type: DataTypes.DECIMAL,
      
      

      },

unit: {
        type: DataTypes.TEXT,
      
      

      },

confidence_level: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  test_result_points.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.test_result_points.belongsTo(db.metallurgical_tests, {
      as: 'metallurgical_test',
      foreignKey: {
        name: 'metallurgical_testId',
      },
      constraints: false,
    });

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




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

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



  return test_result_points;
};


