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

collection_name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  recipe_collections.associate = (db) => {

    db.recipe_collections.belongsToMany(db.recipes, {
      as: 'recipes',
      foreignKey: {
        name: 'recipe_collections_recipesId',
      },
      constraints: false,
      through: 'recipe_collectionsRecipesRecipes',
    });

    db.recipe_collections.belongsToMany(db.recipes, {
      as: 'recipes_filter',
      foreignKey: {
        name: 'recipe_collections_recipesId',
      },
      constraints: false,
      through: 'recipe_collectionsRecipesRecipes',
    });


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


















































































































//end loop



    db.recipe_collections.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return recipe_collections;
};


