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

sequence_number: {
        type: DataTypes.INTEGER,
      
      

      },

check_name: {
        type: DataTypes.TEXT,
      
      

      },

value_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"pass_fail",


"numeric",


"text"

        ],

      },

lower_limit: {
        type: DataTypes.DECIMAL,
      
      

      },

upper_limit: {
        type: DataTypes.DECIMAL,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

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

  qa_checklist_items.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_checklist_items.hasMany(db.qa_measurements, {
      as: 'qa_measurements_qa_checklist_item',
      foreignKey: {
          name: 'qa_checklist_itemId',
      },
      constraints: false,
    });






//end loop



    db.qa_checklist_items.belongsTo(db.qa_checklists, {
      as: 'qa_checklist',
      foreignKey: {
        name: 'qa_checklistId',
      },
      constraints: false,
    });




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

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



  return qa_checklist_items;
};


