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

generated_at: {
        type: DataTypes.DATE,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  grocery_lists.associate = (db) => {


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








































    db.grocery_lists.hasMany(db.grocery_items, {
      as: 'grocery_items_grocery_list',
      foreignKey: {
          name: 'grocery_listId',
      },
      constraints: false,
    });











































































//end loop



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

    db.grocery_lists.belongsTo(db.meal_plans, {
      as: 'meal_plan',
      foreignKey: {
        name: 'meal_planId',
      },
      constraints: false,
    });




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

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



  return grocery_lists;
};


