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

name: {
        type: DataTypes.TEXT,
      
      

      },

data_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"numeric",


"text",


"boolean",


"enum"

        ],

      },

target_value: {
        type: DataTypes.DECIMAL,
      
      

      },

lower_limit: {
        type: DataTypes.DECIMAL,
      
      

      },

upper_limit: {
        type: DataTypes.DECIMAL,
      
      

      },

unit: {
        type: DataTypes.TEXT,
      
      

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"minor",


"major",


"critical"

        ],

      },

method: {
        type: DataTypes.TEXT,
      
      

      },

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

  qa_characteristics.associate = (db) => {


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



































    db.qa_characteristics.hasMany(db.qa_results, {
      as: 'qa_results_qa_characteristic',
      foreignKey: {
          name: 'qa_characteristicId',
      },
      constraints: false,
    });











//end loop



    db.qa_characteristics.belongsTo(db.qa_plans, {
      as: 'qa_plan',
      foreignKey: {
        name: 'qa_planId',
      },
      constraints: false,
    });




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

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



  return qa_characteristics;
};


