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

quantity: {
        type: DataTypes.DECIMAL,
      
      

      },

quantity_unit: {
        type: DataTypes.TEXT,
      
      

      },

calories: {
        type: DataTypes.INTEGER,
      
      

      },

protein_g: {
        type: DataTypes.DECIMAL,
      
      

      },

carbs_g: {
        type: DataTypes.DECIMAL,
      
      

      },

fat_g: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  meal_items.associate = (db) => {


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


















































































































//end loop



    db.meal_items.belongsTo(db.meals, {
      as: 'meal',
      foreignKey: {
        name: 'mealId',
      },
      constraints: false,
    });

    db.meal_items.belongsTo(db.foods, {
      as: 'food',
      foreignKey: {
        name: 'foodId',
      },
      constraints: false,
    });

    db.meal_items.belongsTo(db.recipes, {
      as: 'recipe',
      foreignKey: {
        name: 'recipeId',
      },
      constraints: false,
    });




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

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



  return meal_items;
};


