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

effective_from: {
        type: DataTypes.DATE,
      
      

      },

effective_to: {
        type: DataTypes.DATE,
      
      

      },

bmr: {
        type: DataTypes.DECIMAL,
      
      

      },

tdee: {
        type: DataTypes.DECIMAL,
      
      

      },

goal_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"deficit",


"maintenance",


"surplus"

        ],

      },

calorie_target: {
        type: DataTypes.INTEGER,
      
      

      },

protein_target_g: {
        type: DataTypes.DECIMAL,
      
      

      },

carb_target_g: {
        type: DataTypes.DECIMAL,
      
      

      },

fat_target_g: {
        type: DataTypes.DECIMAL,
      
      

      },

macro_preset_name: {
        type: DataTypes.TEXT,
      
      

      },

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

  nutrition_targets.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.nutrition_targets.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return nutrition_targets;
};


