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

name: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  frequently_bought_together_groups.associate = (db) => {

    db.frequently_bought_together_groups.belongsToMany(db.frequently_bought_together_items, {
      as: 'items',
      foreignKey: {
        name: 'frequently_bought_together_groups_itemsId',
      },
      constraints: false,
      through: 'frequently_bought_together_groupsItemsFrequently_bought_together_items',
    });

    db.frequently_bought_together_groups.belongsToMany(db.frequently_bought_together_items, {
      as: 'items_filter',
      foreignKey: {
        name: 'frequently_bought_together_groups_itemsId',
      },
      constraints: false,
      through: 'frequently_bought_together_groupsItemsFrequently_bought_together_items',
    });


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





























    db.frequently_bought_together_groups.hasMany(db.frequently_bought_together_items, {
      as: 'frequently_bought_together_items_group',
      foreignKey: {
          name: 'groupId',
      },
      constraints: false,
    });
















//end loop



    db.frequently_bought_together_groups.belongsTo(db.products, {
      as: 'primary_product',
      foreignKey: {
        name: 'primary_productId',
      },
      constraints: false,
    });




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

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



  return frequently_bought_together_groups;
};


