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

name: {
        type: DataTypes.TEXT,
      
      

      },

unit: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  chemical_products.associate = (db) => {


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











    db.chemical_products.hasMany(db.job_chemical_usages, {
      as: 'job_chemical_usages_chemical_product',
      foreignKey: {
          name: 'chemical_productId',
      },
      constraints: false,
    });





//end loop






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

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



  return chemical_products;
};


