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

result: {
        type: DataTypes.ENUM,
      
      

        values: [

"pass",


"fail",


"not_applicable"

        ],

      },

numeric_value: {
        type: DataTypes.DECIMAL,
      
      

      },

text_value: {
        type: DataTypes.TEXT,
      
      

      },

recorded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  qa_measurements.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.qa_measurements.belongsTo(db.qa_inspections, {
      as: 'qa_inspection',
      foreignKey: {
        name: 'qa_inspectionId',
      },
      constraints: false,
    });

    db.qa_measurements.belongsTo(db.qa_checklist_items, {
      as: 'qa_checklist_item',
      foreignKey: {
        name: 'qa_checklist_itemId',
      },
      constraints: false,
    });

    db.qa_measurements.belongsTo(db.users, {
      as: 'recorded_by',
      foreignKey: {
        name: 'recorded_byId',
      },
      constraints: false,
    });




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

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



  return qa_measurements;
};


